62.0k views
3 votes
Consider the following code:

x = 5 % 4
if (x == 1):
print (1)
elif (x == 2):
print (2)
elif (x == 3):
print (3)
else:
print (4)
What is output?

User Aaron He
by
6.5k points

1 Answer

6 votes

Answer:

1

Step-by-step explanation:

The % (modulus) operator takes the remainder of the dividend when divided by the divisor. In this case, x = 1 since it is the remainder of 5 ÷ 4. Since x satisfies the condition of the first if-statement (x == 1), 1 is the output of this code.

Hope this helps :)

User Onmylemon
by
6.2k points