Write a Python program to read 10 numbers and find their sum and average. In this Python example, for loop range iterates from 1 to 10 and read user entered 10 numbers and finds the sum while entering. Next, we divide that sum by ten to get the average.
Sum = 0 print("Please Enter 10 Numbers\n") for i in range(1, 11): num = int(input("Number %d = " %i)) Sum = Sum + num avg = Sum / 10 print("The Sum of 10 Numbers = ", Sum) print("The Average of 10 Numbers = ", avg)
This Python program reads 10 numbers from user input and finds their sum and average using a while loop.
Sum = 0 print("Please Enter 10 Numbers\n") i = 1 while(i <= 10): num = int(input("Number %d = " %i)) Sum = Sum + num i = i + 1 avg = Sum / 10 print("The Sum of 10 Numbers = ", Sum) print("The Average of 10 Numbers = ", avg)
Please Enter 10 Numbers
Number 1 = 34
Number 2 = 2
Number 3 = 65
Number 4 = 45
Number 5 = 76
Number 6 = -98
Number 7 = 33
Number 8 = 66
Number 9 = 88
Number 10 = 122
The Sum of 10 Numbers = 433
The Average of 10 Numbers = 43.3