Python Program to find biggest of three numbers
Program
a = float(input("Enter the first number: "))
b = float(input("Enter the second number: "))
c = float(input("Enter the third number: "))
if(a > b) and (a > c):
largest = a
elif (b > c):
largest = b
else:
largest = c
print "Largest number is: ", largest
This program takes three numbers as input and determines the largest using conditional statements.
a = float(input("Enter the first number: "))
b = float(input("Enter the second number: "))
c = float(input("Enter the third number: "))
input()
function takes user input as a string.float()
function converts the input into a floating-point number.- The user enters three numbers:
a
,b
, andc
.
if (a > b) and (a > c):
largest = a
elif (b > c):
largest = b
else:
largest = c
- Compares
a
,b
, andc
usingif-elif-else
conditions. - If
a
is greater than bothb
andc
,largest
is set toa
. - Else if
b
is greater thanc
,largest
is set tob
. - Otherwise,
largest
is set toc
.
Key Takeaways:
- Uses
if-elif-else
to compare three numbers. - Handles floating-point numbers for greater precision.
- Handles cases where numbers are equal.
Output 1
Enter the first number: 65
Enter the second number: 12.3
Enter the third number: 54.1987
Largest number is: 65.0
Output 2
Enter the first number: 19
Enter the second number: 34.85
Enter the third number: 9.011
Largest number is: 34.85
Output 3
Enter the first number: 65
Enter the second number: 1
Enter the third number: 98
Largest number is: 98.0