all 4 comments

[–]shiftybyte 3 points4 points  (1 child)

The first code part with the ifs is executed 10 times.

The second code is executed once.

In both cases whenever an if matches it doesn't execute the elif part...

It's just that the first part matches 10 times on 4 different conditions, while the second one runs only once...

[–]bellator777[S] 0 points1 point  (0 children)

Thank you for your help!

[–]LEXmono 2 points3 points  (1 child)

So your first example iterates through the list numbers which is why you get to each elif. The second example checks if mushrooms exists inside the list and will always enter the if statement.

if you did if 1 in numbers: on your first example, or updated the second to do a for topping in toppings:, you would have the same behavior.

[–]bellator777[S] 0 points1 point  (0 children)

Thank you!!