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.
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}")
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
- 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