← Quiz: Software Architecture Styles: all 10 questions
Quiz: Software Architecture Styles · Question 3 of 10
What does this print? (code)
What does this print?
class Model:
def __init__(self):
self.data = {'a': 3, 'b': 0}
def stock(self, item):
return self.data.get(item)
def view(item, qty):
return f'{item}: in stock' if qty else f'{item}: out of stock'
def controller(m, item):
q = m.stock(item)
return 'unknown item' if q is None else view(item, q)
m = Model()
print(controller(m, 'b'), '|', controller(m, 'z'))
- A.b: in stock | unknown item
- B.b: out of stock | unknown item
- C.b: out of stock | z: out of stock
- D.unknown item | unknown item
Answer & explanation
Correct answer: b: out of stock | unknown item
'b' has quantity 0, which is falsy, so the view says out of stock; 'z' is missing, so the controller returns unknown item.
Can you get the rest right without peeking?
Take the timed Quiz: Software Architecture Styles quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →