Quiz Questions, Three Levels Deep

Python for AIHard+10 XP+10

Quiz Questions, Three Levels Deep

A quiz app has three kinds of question. Each level adds one thing to the level above it.

Question(text, answer)

  • check(guess) returns True if the guess matches the answer, ignoring capital letters and spaces at either end. So " paris " matches "Paris".

TimedQuestion(text, answer, seconds), a child of Question

  • Stores seconds, the time limit. Let the parent set up text and answer.
  • points(guess, taken) returns:
    • 0 if the guess is wrong,
    • 10 if it's right and taken is at most seconds,
    • 5 if it's right but too slow.

BonusQuestion(text, answer, seconds, bonus), a child of TimedQuestion

  • bonus defaults to 5. Let the parent set up everything else.
  • points(guess, taken) returns the parent's points, plus bonus only when the parent's points are 10.

Examples

TimedQuestion("Capital of France?", "Paris", 10).points(" paris ", 8)
returns 10
BonusQuestion("2 + 2?", "4", 5).points("4", 6)
returns 5

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run