148k views
0 votes
What is the output of the following code?

x = 0
if x < 4:
x = x + 1
print(""x is""x)
A. x is 0
B. x is 1
C. x is 2
D. x is 3
E. x is 4"

User Maxim
by
8.4k points

1 Answer

2 votes

Answer:

option E

x is 4

Step-by-step explanation:

x = 0

if x < 4: yes x is less than 4 so the if statement will be executed

x = x + 1 x = 0 + 1, x = 1 for next iteration

x = 1 + 1, x = 2

x = 2 + 1, x = 3

x = 3 + 1, x = 4

if statement keeps on executing till x < 4

print (""x is "" x)

output will be, x is 4

User Kilian Foth
by
9.2k points

No related questions found