Python: Print the Middle of Three Numbers if Distinct

Опубликовано: 19 Июль 2026
на канале: Explain IT Again
26
0

QUESTION
Create a program that asks for three integer inputs. If at least two numbers from the three numbers are equal, then print the statement “There are similar numbers in your inputs” and terminate the program. If the three inputs are distinct, then print the middle number.
ANSWER
num = int(input("Enter three digits: "))
if len(str(num)) != 3: print("Try Again. Enter 3 digits")
else:
n1, n2, n3 = int(str(num)[0]), int(str(num)[1]), int(str(num)[2])
if n1 == n2 or n2 == n3 or n1 == n3:
print("There are similar numbers in your inputs.")
else:
print(n2)