logo

Crowdly

Browser

Add to Chrome

Qu'affiche le code Python suivant ? def cc(*cmds): stack = [] output...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

Qu'affiche le code Python suivant ?

def cc(*cmds):

stack = []

outputs = []

for c in cmds:

match c:

case ("push", x):

stack.append(x)

case ("pop",):

if stack:

outputs.append(stack.pop())

case ("sum",):

if len(stack) >= 2:

a = stack.pop()

b = stack.pop()

stack.append(a + b)

case _:

pass

return outputs

print(cc(("push", 1), ("pop",), ("pop",)),

cc(("push", 1), ("push", -1), ("sum",), ("pop",)),

cc(("pop",),))

0%
0%
0%
100%
0%
More questions like this

Want instant access to all verified answers on moodle.ipsa.fr?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome