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:

Glendora
2 hours ago
I'm pretty sure the code outputs 2. That's just how the math works out, right?
upvoted 0 times
...
Lorrine
6 days ago
I'm not sure, but I think the code outputs 3.
upvoted 0 times
...
Melodie
9 days ago
I believe the code enters an infinite loop.
upvoted 0 times
...
Hui
11 days ago
I think the code outputs 2.
upvoted 0 times
...

Save Cancel