Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Python Institute Exam PCEP-30-02 Topic 1 Question 13 Discussion

Actual exam question for Python Institute's PCEP-30-02 exam
Question #: 13
Topic #: 1
[All PCEP-30-02 Questions]

What happens when the user runs the following code?

Show Suggested Answer Hide Answer
Suggested Answer: C

The code snippet that you have sent is a loop that checks if a variable ''floor'' is less than or equal to 0 and prints a string accordingly. The code is as follows:

floor = 5 while floor > 0: print(''+'') floor = floor - 1

The code starts with assigning the value 5 to the variable ''floor''. Then, it enters a while loop that repeats as long as the condition ''floor > 0'' is true. Inside the loop, the code prints a ''+'' symbol to the screen, and then subtracts 1 from the value of ''floor''. The loop ends when ''floor'' becomes 0 or negative, and the code exits.

The code outputs five ''+'' symbols to the screen, one for each iteration of the loop. Therefore, the correct answer is C. five.


Contribute your Thoughts:

Silvana
20 days ago
I've got a loop that'll really make your head spin - it's called the 'Hamster Wheel of Doom'! Bet this code could give it a run for its money.
upvoted 0 times
Vannessa
2 days ago
What's the code you're talking about?
upvoted 0 times
...
...
Freida
25 days ago
1? Really? That's about as obvious as a cow in a chicken coop. Let's hope the rest of the test isn't this easy.
upvoted 0 times
...
Celestine
26 days ago
Wait, is this a trick question? I'm going with 3 just to be safe. You can never be too careful on these exams!
upvoted 0 times
...
Lang
28 days ago
Hmm, I'm thinking it's an infinite loop. Those nested loops can be tricky, you know? Gotta watch out for those.
upvoted 0 times
...
Glendora
2 months ago
I'm pretty sure the code outputs 2. That's just how the math works out, right?
upvoted 0 times
Ettie
18 days ago
Actually, the code outputs 1. It's a common mistake to think it's 2.
upvoted 0 times
...
Ettie
23 days ago
Yes, you're correct. The code outputs 2.
upvoted 0 times
...
...
Lorrine
2 months ago
I'm not sure, but I think the code outputs 3.
upvoted 0 times
...
Melodie
2 months ago
I believe the code enters an infinite loop.
upvoted 0 times
...
Hui
2 months ago
I think the code outputs 2.
upvoted 0 times
...

Save Cancel