What is the output of the following piece of code if the user enters two lines containing 3 and 2 respectively?
x = int(input()) y = int(input()) x = x % y x = x % y y = y % x print(y)
- 3
- 1
- 2
- 0
Explanation: Let’s analyze what happens:
- x = 3 and y = 2
- Line 3: x = 3 % 2 = 1
- Line 4: x = 1 % 2 = 1
- Line 5: x = 2 % 1 = 0
- the result is printed to the screen.
More Questions: Python Essentials 1 (PE1) Course Final Test
Please login or Register to submit your answer