KnowledgeBoat Logo

Computer Science

Write a short program to find average of list of numbers entered through keyboard.

Python

Python Control Flow

32 Likes

Answer

sum = count = 0

print("Enter numbers")
print("(Enter 'q' to see the average)")

while True :
    n = input()
    if n == 'q' or n == 'Q' :
        break
    else :
        sum += int(n)
        count += 1

avg = sum / count
print("Average = ", avg)

Output

Enter numbers
(Enter 'q' to see the average)
2
5
7
15
12
q
Average =  8.2

Answered By

9 Likes


Related Questions