Python Program to find the Largest of Three Numbers
In this tutorial, we will discuss a Python Program to find the Largest of Three Numbers.
This is a common problem that can be solved using simple conditional statements.
Related: Python Program for Compound Interest Calculator
Program code for finding the largest of three numbers using Python
# Largest of Three Numbers in Python def find_largest(a, b, c): if a >= b and a >= c: return a elif b >= a and b >= c: return b else: return c num1 = int(input("Enter first number: ")) num2 = int(input("Enter second number: ")) num3 = int(input("Enter third number: ")) print(f"The largest of {num1}, {num2}, and {num3} is {find_largest(num1, num2, num3)}.")
Explanation
- Function Definition: The
find_largest
function takes three integersa
,b
, andc
as input and returns the largest of the three numbers. - Conditional Statements: The function uses conditional statements to compare the numbers and determine the largest.
- Main Program: The program prompts the user to enter three numbers and then finds the largest of the three using the
find_largest
function.
Output
- When you run the above program, it will prompt you to enter three numbers.
- After entering the numbers, it will find the largest of the three and print the result.
Conclusion
- In this tutorial, we learned how to find the largest of three given numbers using a Python program.
- Understanding this concept is essential for solving various mathematical problems and competitive programming challenges.
- Practice this example to enhance your programming skills and understanding of conditional statements.