~1 min read • Updated Oct 7, 2025
Program Overview
This Python program reads an integer n from the user, representing the number of values to be entered.
It then reads n numbers and calculates their average.
The result is displayed with two decimal places.
Python Code:
n = int(input("Enter the number of values: "))
total = 0
for i in range(n):
num = float(input(f"Enter number {i + 1}: "))
total += num
average = total / n
print(f"Average: {average:.2f}")
Sample Output:
Enter the number of values: 4
Enter number 1: 12
Enter number 2: 15
Enter number 3: 10
Enter number 4: 13
Average: 12.50
Step-by-Step Explanation:
- The program first reads the number of values n
- It then loops n times to read each number
- Each number is added to a running total
- After the loop, the average is calculated using total / n
- The result is printed with two decimal places
Written & researched by Dr. Shahin Siami