← Quiz: Semaphores and Classic Problems: all 9 questions
Quiz: Semaphores and Classic Problems · Question 8 of 9
What does this print? (code)
What does this print?
s = 7
for op in ["P"] * 20 + ["V"] * 15:
s = s - 1 if op == "P" else s + 1
print(s)
- A.2
- B.−13
- C.22
- D.7
Answer & explanation
Correct answer: 2
7 − 20 + 15 = 2; the order of operations does not change the final value.
Can you get the rest right without peeking?
Take the timed Quiz: Semaphores and Classic Problems quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →