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, and c.
if (a > b) and (a > c):
    largest = a
elif (b > c):
    largest = b
else:
    largest = c
  • Compares a, b, and c using if-elif-else conditions.
  • If a is greater than both b and c, largest is set to a.
  • Else if b is greater than c, largest is set to b.
  • Otherwise, largest is set to c.

Key Takeaways:

  1. Uses if-elif-else to compare three numbers.
  2. Handles floating-point numbers for greater precision.
  3. 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