🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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'))
  1. A.b: in stock | unknown item
  2. B.b: out of stock | unknown item
  3. C.b: out of stock | z: out of stock
  4. 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 →