Take Three Numbers and Print the Largest

Compare three numbers and find the largest.

BeginnerPhase 1 - Level 1: Simple ConditionsExample 7 of 10
take-three-numbers-and-print-the-largest.py
1# Take three numbers as input
2num1 = float(input("Enter first number: "))
3num2 = float(input("Enter second number: "))
4num3 = float(input("Enter third number: "))
5
6# Find largest number
7if num1 >= num2 and num1 >= num3:
8 largest = num1
9elif num2 >= num1 and num2 >= num3:
10 largest = num2
11else:
12 largest = num3
13
14print(f"Largest number: {largest}")

Output

Enter first number: 10
Enter second number: 25
Enter third number: 15
Largest number: 25.0

What's going on

Compare three numbers by checking each one against the other two.

Key Concepts:

Check if num1 is >= both num2 and num3
Else check if num2 is >= both num1 and num3
Otherwise num3 is the largest
Use and to ensure a number is greater than or equal to both others