Last Updated: January 3, 2026
31 quizzes
Complete the code so that payment_processor.charge is called with the total_amount value
result = payment_processor.(total_amount)Click an option to fill the blank:
Complete the line so that notifier.send_message is used to send the text variable
notifier.(text)Click an option to fill the blank:
Complete the line so that the audio_player object plays its content using its play method
audio_player.__()Click an option to fill the blank:
In Python OOP, what does runtime polymorphism mainly rely on?
What is the main idea of duck typing in Python?
Which statement about abstract classes created with abc.ABC is true?
What happens if a subclass of an ABC does not implement all abstract methods?
Why would you define an interface-style ABC like Shape with an abstract area method?
Which best describes a Protocol from the typing module?
In duck typing, how should a function log_message(logger, message) decide whether logger is valid?
Which situation is the clearest use case for polymorphism?
Which is a benefit of programming to an interface (ABC or Protocol) instead of a concrete class?
Which decorator from the abc module marks a method as abstract?
When using Protocol for static type checking, when is compatibility with a Protocol typically verified?
Order the steps to define an abstract base class PaymentMethod and a concrete CardPayment that can be instantiated.
Drag and drop to reorder, or use the arrows.
Order the steps to use a Protocol for a notifier that supports send_message for static type checking.
Drag and drop to reorder, or use the arrows.
What is the output of this code using runtime polymorphism?
1class Report:
2 def generate(self):
3 return "Base report"
4
5class PdfReport(Report):
6 def generate(self):
7 return "PDF report"
8
9class HtmlReport(Report):
10 def generate(self):
11 return "HTML report"
12
13reports = [PdfReport(), HtmlReport()]
14print(reports[1].generate())What is the output of this duck typing example?
1class JsonSerializer:
2 def serialize(self, data):
3 return "json:" + str(data)
4
5class XmlSerializer:
6 def serialize(self, data):
7 return "xml:" + str(data)
8
9def dump(serializer, value):
10 return serializer.serialize(value)
11
12print(dump(XmlSerializer(), 10))What is the output when accessing an abstract property implementation?
1from abc import ABC, abstractmethod
2
3class DataSource(ABC):
4 @property
5 @abstractmethod
6 def name(self):
7 pass
8
9class ApiSource(DataSource):
10 @property
11 def name(self):
12 return "Public API"
13
14source = ApiSource()
15print(source.name)What is printed when using a Protocol-compatible object without explicit inheritance?
1from typing import Protocol
2
3class Runner(Protocol):
4 def run(self) -> str:
5 ...
6
7class Job:
8 def run(self) -> str:
9 return "job running"
10
11def execute(task: Runner) -> None:
12 print(task.run())
13
14execute(Job())What is the output when a subclass does not override a method of the base class?
1class Transport:
2 def start(self):
3 return "generic start"
4
5class Bicycle(Transport):
6 pass
7
8vehicle = Bicycle()
9print(vehicle.start())Find the bug in this code that tries to use an abstract class for shapes.
Click on the line(s) that contain the bug.
from abc import ABC, abstractmethod class Shape(ABC): @abstractmethod def area(self): pass square = Shape()print(square.area())Find the design bug in this duck typing based logger function.
Click on the line(s) that contain the bug.
class ConsoleLogger: def log(self, message): print(message) class FileLogger: def write(self, message): with open('log.txt', 'a') as f: f.write(message + '\n') def log_message(logger, message): if isinstance(logger, ConsoleLogger): logger.log(message) else: logger.write(message)Match each concept to its closest description.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match each Python feature with a realistic usage scenario.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Complete the abstract class and subclass so that all concrete devices implement connect and disconnect.
from abc import ABC, abstractmethodclass Device(ABC): @ def connect(self) -> None: pass @ def disconnect(self) -> None: passclass UsbDevice(Device): def connect(self) -> None: print("USB connected") def disconnect(self) -> None: print("USB disconnected")Click an option to fill blank 1:
Complete the Protocol-based definition so that workers with a run method are accepted.
from typing import Protocolclass Runnable(Protocol): def (self) -> str: ...class Task: def run(self) -> str: return "task done"def execute(job: Runnable) -> None: print(job.())execute(Task())Click an option to fill blank 1:
Fill in the base class for polymorphic notification senders.
from abc import ABC, abstractmethodclass Notifier(): @abstractmethod def send(self, message: str) -> None: passclass EmailNotifier(Notifier): def send(self, message: str) -> None: print("EMAIL:", message)Click an option to fill blank 1:
Complete this duck-typed function to work with any object that has a quack method.
class RealDuck: def quack(self) -> str: return "Quack!"class Person: def quack(self) -> str: return "I'm pretending to be a duck!"def make_it_quack(thing) -> None: sound = thing.() print(sound)make_it_quack(RealDuck())make_it_quack(Person())Click an option to fill blank 1:
Click the line that causes a runtime error because of instantiating an abstract class.
Click on the line to select.
from abc import ABC, abstractmethod class Storage(ABC): @abstractmethod def save(self, data: str) -> None: pass store = Storage()store.save("test")Click the line where duck typing breaks because it assumes a specific concrete type.
Click on the line to select.
class CsvExporter: def export(self, rows): print("csv", rows) class JsonExporter: def export(self, rows): print("json", rows) def export_data(exporter, rows): if type(exporter) is CsvExporter: exporter.export(rows) else: exporter.export(rows)