Python Program to Find the Greatest of Three Numbers

In this tutorial, we will discuss a Python program to find the greatest of three numbers.

Related: Python Program to Calculate the Power of a Number

Program code to find the greatest of three numbers in Python

# Find the Greatest of Three Numbers in Python
def find_greatest(a, b, c):
    if a >= b and a >= c:
        return a
    elif b >= a and b >= c:
        return b
    else:
        return c

num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))
print(f"The greatest of {num1}, {num2}, and {num3} is {find_greatest(num1, num2, num3)}.")

Explanation

  1. Function Definition: The find_greatest function takes three numbers as input and returns the greatest of the three.
  2. Main Program: The program prompts the user to enter three numbers and then finds the greatest using the find_greatest function and prints the result.

Output

Python Program to Find the Greatest of Three Numbers

  • When you run the above program, it will prompt you to enter three numbers.
  • After entering the numbers, it will find the greatest and print the result.

Conclusion

  • In this tutorial, we learned a Python program for finding the greatest of three numbers.
  • Understanding this concept is essential for solving various mathematical problems and enhancing your programming skills.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *