GPYC Exam QuestionsBrowse all questions from this exam

GPYC Exam - Question 15


How many lines will the following code print?

Show Answer
Correct Answer: AB

The code first sets x to 0. It then enters a while True loop where x is incremented by 1, making it 1. The code checks if x is less than 100, which is true, so it prints '1<100' and then executes the break statement, which exits the loop. Only one line is printed before the break statement is executed, so the answer is 1.

Discussion

5 comments
Sign in to comment
block933Option: A
Sep 11, 2021

line 5 needs paranthesis

mrmrmeOption: B
Feb 7, 2022

X starts at 0. Enters while loop, X = 1, first if statement executes, and 1 line is produced, then the break statement ends the loop

kabwitte
Nov 9, 2021

Try py 2

AZIrvThoOption: A
Sep 29, 2023

When running this code, line 5 is identified as a syntax error. Therefore, it returns 0 lines. I did not try this in Python 2.

a29dc2cOption: A
Feb 7, 2024

non parenthesis so the code would crash after if x < 200: