PCEP 30 02 PCEP Certified Entry Level Python Programmer · Free Practice Question Easy
Question 24
How many asterisks (*) does the code output to the screen ?
i = 0
while i !=0:
i//=2
print("**",end="")
else:
print("*")
-
A
3
-
B
1
-
C
2
-
D
0
Reveal correct answer
Correct answer: B
Explanation
In the provided code, there is a while loop that continues to execute as long as i is not equal to 0. However, the loop begins with i initialized to 0, so the condition is not satisfied from the start. As a result, the loop body is never executed, and the else block is executed immediately.
The output of the code will be: one asterisks
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
You must be logged in to post a comment.
