- Code: Select all
`Enter values below (or just press Enter to quit):`

? 1.5

? 2

? 4.7

? 3.3

? 0.8

?

5 values entered

Mean = 2.46

where if the user doesn't input a number and just presses enter it terminates the loop and prints the mean.

I have two problems;

1) When converting input to float, at the end of loop when user presses enter to end loop, it can't float this 'enter' input. How would i get around this? ( maybe convert 'enter' input to = 0 when adding to total? )

2) How would i count the amount of inputs as to divide the total by this number to get the mean?

My code so far is as below;

- Code: Select all
`total= 0`

input_count= # don't know what code to use to count the amount of inputs?

while True:

i=float(input("Enter next number (or just enter to quit): "))

total += i

print("Your input:", i)

if not i:

break

print("While loop has exited")

mean = total/input_count

print( str(mean))

Thank for any help, ben