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 PCEP-30-02 Exam - Topic 1 Question 13 Discussion

What happens when the user runs the following code?
C) The code enters an infinite loop.
A) The code outputs 3.
B) The code outputs 2.
D) The code outputs 1.

Python Institute PCEP-30-02 Exam - 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:

0/2000 characters
Cyndy
7 months ago
I’m surprised this code even runs without errors!
upvoted 0 times
...
Carmen
8 months ago
Wait, are you sure it doesn't just output 1?
upvoted 0 times
...
Ulysses
8 months ago
Nah, it definitely goes into an infinite loop.
upvoted 0 times
...
Mitsue
8 months ago
I think it actually outputs 3!
upvoted 0 times
...
Marti
8 months ago
The code outputs 2.
upvoted 0 times
...
Stephaine
9 months ago
I feel like the output is 1, but I need to double-check how the variables are being manipulated.
upvoted 0 times
...
Jeff
9 months ago
I'm leaning towards it entering an infinite loop, but I can't recall the exact logic behind it.
upvoted 0 times
...
Marnie
9 months ago
I remember a similar question where the output was based on the loop condition. Could it be 3?
upvoted 0 times
...
Marti
9 months ago
I think the code should output 2, but I'm not entirely sure how the loop works in this case.
upvoted 0 times
...
Maddie
9 months ago
Hmm, I'm not sure about this one. I'll make my best guess, but I might need to come back to it if I'm still unsure.
upvoted 0 times
...
Hailey
9 months ago
I think I've got it! The output should be 2, since the loop runs twice and the variable 'x' is incremented each time.
upvoted 0 times
...
Jacklyn
9 months ago
I'm a bit confused by the nested loops and the way the variables are being updated. I'll need to re-read the code a few times to make sure I understand it.
upvoted 0 times
...
Dierdre
9 months ago
Okay, let me think this through. The key is understanding how the loop and the variable assignments work together.
upvoted 0 times
...
Weldon
9 months ago
Hmm, this looks like a tricky one. I'll need to carefully trace the logic step-by-step to figure out what's happening.
upvoted 0 times
...
Barabara
9 months ago
This question seems straightforward. I think childhood immunizations would be the best answer since they provide major health benefits at a relatively low cost.
upvoted 0 times
...
Marleen
9 months ago
This question seems straightforward, I'm pretty confident I know the answer.
upvoted 0 times
...
Staci
9 months ago
Easy! The Windows Upgrade Advisor is the tool you want to use. It's designed to analyze your system and let you know if it's ready for the Windows 7 upgrade. Piece of cake.
upvoted 0 times
...
Silvana
1 year 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
1 year ago
I'm not sure, but I think it enters an infinite loop.
upvoted 0 times
...
Vannessa
1 year ago
I think it might output 2.
upvoted 0 times
...
Vannessa
1 year ago
What's the code you're talking about?
upvoted 0 times
...
...
Freida
1 year 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
1 year 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
1 year 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
Thaddeus
1 year ago
User1: I'll go with option C then, the code enters an infinite loop.
upvoted 0 times
...
Gail
1 year ago
User2: Yeah, nested loops can definitely cause some unexpected behavior.
upvoted 0 times
...
Shakira
1 year ago
User1: I think it's an infinite loop too. Nested loops can be tricky.
upvoted 0 times
...
...
Glendora
1 year ago
I'm pretty sure the code outputs 2. That's just how the math works out, right?
upvoted 0 times
Ettie
1 year ago
Actually, the code outputs 1. It's a common mistake to think it's 2.
upvoted 0 times
...
Ettie
1 year ago
Yes, you're correct. The code outputs 2.
upvoted 0 times
...
...
Lorrine
1 year ago
I'm not sure, but I think the code outputs 3.
upvoted 0 times
...
Melodie
1 year ago
I believe the code enters an infinite loop.
upvoted 0 times
...
Hui
1 year ago
I think the code outputs 2.
upvoted 0 times
...

Save Cancel