Objective: Write a program to find the greatest of three numbers.
Way 1:
num1 = int(input("Enter 1 number: "))
num2 = int(input("Enter 2 number: "))
num3 = int(input("Enter 3 number: "))
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
print("The largest number is", largest)
Output:
Way 2:
num1 = int(input("Enter 1 number: "))
num2 = int(input("Enter 2 number: "))
num3 = int(input("Enter 3 number: "))
if num1 >= num2:
if num1 >= num3:
largest = num1
else:
largest = num3
else:
if num2 >= num3:
largest = num2
else:
largest = num3
print("The largest number is", largest)
No comments:
Post a Comment