0

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)
2
  • "Will not work" isn't helpful. Errors (provide full traceback)? Unexpected outputs (provide inputs and expected and actual outputs)? Is this python 3.x or 2.x? Commented Mar 8, 2014 at 21:22
  • Hi @dkahl9668 ! Please, would you be so kind to mark the answer as correct if the problem is already solved? Thanks in advance and have a nice day! Commented Mar 9, 2014 at 7:52

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi @TylerAndFriends ! It is always nice to read a comment as the one you have written. Unfortunately this is not the most common thing in these days, full of silly users who think they know everything. Cheers!
0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.