Reputation: 1
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
Reputation: 605
You can add from __future__ import division
and it will make all divisions be floats.
Upvotes: 0
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