dkahl9668
dkahl9668

Reputation: 1

Python average input not working

I am trying to get average times of the speed skaters with Python and my code will not work. I have searched all over trying to find an answer and I am completely stumped.

print("Enter the skater times in seconds. Input -1 to finish and calculate.")

count = 0
sum = 0.0
number = 1

while number != -1:
    number = input("Enter skater time in seconds: ")
    if number != 0:
        count = count + 1
        sum = sum + number

print ("The number of skaters was: ", count)
print ("The average skater time was:", sum / count)

Upvotes: 0

Views: 145

Answers (2)

ifryed
ifryed

Reputation: 605

You can add from __future__ import division and it will make all divisions be floats.

Upvotes: 0

Javier
Javier

Reputation: 1087

The if clause must be:

if number > 0:

Otherwise you are considering the last one, whose value is -1

Edit

I think it has nothing to do with integer division. It is only the if clause.

Upvotes: 3

Related Questions