Independence Day Deal! Unlock 25% OFF Today – Limited-Time Offer - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

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

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

What is the expected result of running 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:

Brianne
1 months ago
Haha, this is a tricky one. I'm gonna have to go with C, though. Dividing by zero is like trying to give a high-five to a ghost - it just ain't gonna work!
upvoted 0 times
...
Tommy
1 months ago
I'm gonna go with B. The code increments `x` after the division, so the final value of `x` should be 2.
upvoted 0 times
Joanne
2 days ago
User 3: I'm not sure, but I'll go with B as well.
upvoted 0 times
...
Lon
9 days ago
User 2: Yeah, I agree. It should print 2.
upvoted 0 times
...
Rosann
24 days ago
User 1: I think the answer is B.
upvoted 0 times
...
...
Deonna
2 months ago
I'm pretty sure the answer is D. The code initializes the variable `x` to 0, and then tries to divide 1 by `x`, which should result in 0.
upvoted 0 times
Skye
6 days ago
I'm pretty sure the answer is D. The code initializes the variable `x` to 0, and then tries to divide 1 by `x`, which should result in 0.
upvoted 0 times
...
Tambra
8 days ago
D) The code prints 0
upvoted 0 times
...
Kaitlyn
9 days ago
C) The code raises an unhandled exception.
upvoted 0 times
...
Reuben
16 days ago
B) The code prints 2
upvoted 0 times
...
Cora
23 days ago
A) The code prints 1 .
upvoted 0 times
...
...
Terry
2 months ago
Hmm, I think the correct answer is C. The code looks like it's trying to divide by zero, which should raise an unhandled exception.
upvoted 0 times
Jonelle
19 days ago
I believe the correct answer is C, it will raise an unhandled exception.
upvoted 0 times
...
Paola
1 months ago
I'm pretty sure it will print 1, not raise an exception.
upvoted 0 times
...
Iluminada
1 months ago
I think it will print 0 because the denominator is 0.
upvoted 0 times
...
Dexter
1 months ago
I agree, the code will raise an unhandled exception.
upvoted 0 times
...
...
Luis
2 months ago
Hmm, now I'm not sure. Let's analyze the code again.
upvoted 0 times
...
Nadine
3 months ago
I disagree, I believe the code will print 0, so option D.
upvoted 0 times
...
Luis
3 months ago
I think the expected result is option A.
upvoted 0 times
...

Save Cancel