168k views
22 votes
Write a program that takes three numbers as input from the user, and prints the largest.

Sample Run
Enter a number: 20
Enter a number: 50
Enter a number: 5

Largest: 50

2 Answers

5 votes

Answer:

x=int(input("Enter a number: "))

y=int(input("Enter a number: "))

z=int(input("Enter a number: "))

print("Largest: "+ str(max(x,y,z)))

Step-by-step explanation:

Got it right and I hope this helps :)

User Thisisrandy
by
4.2k points
7 votes

Answer:

In Python:

n1 = int(input("Enter a number: "))

n2 = int(input("Enter a number: "))

n3 = int(input("Enter a number: "))

if n1 >= n2 and n1 >= n3:

print("Largest: "+str(n1))

elif n2 >= n1 and n2 >= n3:

print("Largest: "+str(n2))

else:

print("Largest: "+str(n3))

Step-by-step explanation:

The next three lines get three numbers from the user

n1 = int(input("Enter a number: "))

n2 = int(input("Enter a number: "))

n3 = int(input("Enter a number: "))

This checks if the first number is greater than the other two. If yes, the first number is printed as the largest

if n1 >= n2 and n1 >= n3:

print("Largest: "+str(n1))

This checks if the second number is greater than the other two. If yes, the second number is printed as the largest

elif n2 >= n1 and n2 >= n3:

print("Largest: "+str(n2))

This prints the third number as the largest, if the other two conditions fail

else:

print("Largest: "+str(n3))

User Metagrapher
by
4.9k points