Exam GPYC All QuestionsBrowse all questions from this exam
Question 15

How many lines will the following code print?

    Correct Answer: B

    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
block933Option: A

line 5 needs paranthesis

mrmrmeOption: B

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

a29dc2cOption: A

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

AZIrvThoOption: A

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.

kabwitte

Try py 2