In: Computer Science
Python Jupiter Notebook
Write a program that keeps getting a set of numbers from user
until the user enters "done". Then shows the
count, total, and
average of the entered numbers.
Example:
Enter a number: 55
Enter a number: 90
Enter a number: 12
Enter a number: done
You entered 3 numbers, total is 157, average is 52.33333
Source Code:
Output:
Code in text format (See above images of code for indentation):
#variables to store count and sum
total=0
count=0
while(True):
#read a number
n=input("Enter a number: ")
#if user wants to stop
if(n=="done"):
break
#check for digit
if(n.isdigit()):
#calculate total
total+=int(n)
#increment count
count+=int(1)
#calculate average
average=total/count
#print count,total and average
print("You entered ",count," numbers, total is ",total,", average
is ",average)