10 Loop Problems to Master Loop Logic

btd
9 min readFeb 1, 2024

1. Assuming a user enters 30, 55, and 10 as the input, what is the output of the following code snippet?

num1 = int(input("Enter a number: "))
num2 = int(input("Enter a number: "))
num3 = int(input("Enter a number: "))
if num1 > num2 and num1 > num3 :
print(num1)
elif num2 > num1 and num2 > num3 :
print(num2)
elif num3 > num1 and num3 > num2 :
print(num3)
55
  1. The user enters three numbers: 30, 55, and 10.
  2. Each number is stored in variables num1, num2, and num3, respectively.
  3. The code then checks each number to determine the largest one using a series of if and elif statements:
  • The first if statement checks if num1 is greater than both num2 and num3.
  • The second elif statement checks if num2 is greater than both num1 and num3.
  • The third elif statement checks if num3 is greater than both num1 and num2.

4. Based on the conditions, the code prints the largest number among the three.

Let’s break it down:

First Iteration:

  • User input: num1 = 30
  • Condition num1 > num2 and num1 > num3 evaluates to False (30 is…

--

--