~1 min read • Updated Oct 11, 2025
Program Overview
This Python program reads three numbers from the user.
It sends them to a method that calculates their average.
The result is returned to the main program and displayed.
This exercise helps practice method definition, parameter passing, and basic arithmetic.
Python Code:
def calculate_average(a, b, c):
return (a + b + c) / 3
# Run the program
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))
average = calculate_average(num1, num2, num3)
print(f"The average is: {average:.2f}")
Sample Output (input: 4, 7, 10):
The average is: 7.00
Step-by-Step Explanation:
- The program reads three numbers from the user
- It sends them to a method called calculate_average
- The method adds the numbers and divides the sum by 3
- The result is returned and printed with two decimal places
Written & researched by Dr. Shahin Siami