Python · Exercise 6 of 6 Previous
Advanced
A swappable client with a dataclass result
Write a dataclass Reply with fields text: str and ok: bool = True.
Write a class FakeClient with __init__(self, answer) storing it, a list calls (a new empty list for each FakeClient), and a method complete(prompt) that records the prompt in calls and returns Reply(self.answer).
Write a function ask(client, question) that calls client.complete("Q: " + question) and returns the reply's text.
What Check tests
Reply('hi')has ok set to True and compares by valueaskreturns the reply text- The prompt is sent as 'Q: ' plus the question
- Each FakeClient has its own call list
- Any object with
completeworks
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.