← Quiz: Design Patterns: all 10 questions
Quiz: Design Patterns · Question 7 of 10
What does this print? (code)
What does this print?
def standard(km): return 30 + 5 * km
def express(km): return 60 + 8 * km
class Checkout:
def __init__(self, fee): self.fee = fee
def total(self, cart, km): return cart + self.fee(km)
c = Checkout(standard)
a = c.total(200, 2)
c.fee = express
b = c.total(200, 2)
print(a, b)
- A.240 276
- B.240 240
- C.276 276
- D.230 268
Answer & explanation
Correct answer: 240 276
standard: 200 + 30 + 10 = 240; after swapping the strategy, express: 200 + 60 + 16 = 276.
Can you get the rest right without peeking?
Take the timed Quiz: Design Patterns quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →