336,604 views
23 votes
23 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

Hint: Remember that the numbers should be compared numerically. Any input from the user must be transformed into an integer, but printed as a string. code using python

User RaduM
by
3.3k points

2 Answers

10 votes
10 votes

Final answer:

The Python program takes three user inputs, converts them to integers, compares them using the max() function, and prints the largest number as a string.

Step-by-step explanation:

The student has requested a Python program that takes three numbers as input from the user and prints the largest number among them. Below is a sample code that accomplishes this task:

# Get the three numbers from the user
num1 = int(input('Enter a number: '))
num2 = int(input('Enter a number: '))
num3 = int(input('Enter a number: '))

# Compare the numbers to find the largest
largest = max(num1, num2, num3)

# Print the largest number
print('Largest:', str(largest))

This code will compare the numbers numerically, as required, and will make sure to output the largest number as a string after converting the input to integers.

User Cyberrspiritt
by
3.5k points
18 votes
18 votes

Answer:

a = int(input())

b = int(input())

c = int(input())

print(str(a)) if a >= b and a >= c else print(str(b)) if b >= a and b >= c else print(str(c))

Step-by-step explanation:

a,b,c are your 3 inputs so you can use if elif else statement. I made it into a one-liner because why not. Also, they start out as integers and then are printed as a string.

User Adams
by
2.7k points