92.9k views
2 votes
Create a Python program that asks the user to enter 3 positive numbers. The program should validate that the characters that the user entered formulate a valid positive integer and display an appropriate error message if they do not. The program should use a sequence of conditional (if) statements to display the 3 positive numbers in ascending order.

User Tom St
by
2.8k points

1 Answer

5 votes

Answer:

num1 = input("Enter the first number: ")

num2 = input("Enter the second number: ")

num3 = input("Enter the third number: ")

if num1.isdigit() and num2.isdigit() and num3.isdigit():

num1 = int(num1)

num2 = int(num2)

num3 = int(num3)

if num1 > 0 and num2 > 0 and num3 > 0:

if num1 < num2 and num1 < num3:

if num2 < num3:

print(num1,num2,num3)

else:

print(num1,num3,num2)

elif num2 < num1 and num2 < num3:

if num1 < num3:

print(num2,num1,num3)

else:

print(num2,num3,num1)

else:

if num1 < num2:

print(num3,num1,num2)

else:

print(num3,num2,num1)

else:

print("Please enter positive numbers only.")

else:

print("Please enter positive numbers only.")

User Elsunhoty
by
3.4k points