Reputation: 1297
I have a variable that ranges from 0 to 300 based on some complicated conditions that aren't really relevant.
my problem is that I want to make a timer variable that increases like a clock would. when my variable increases by 1, I want the timer variable to increase by one second. I have this:
for timer in range(1,301):
seconds = range(1,60)
print seconds
the problem is that I need seconds to go from 0.59 to 1.00, not to 1.60 because that's not how time works. I'm thinking I need a minutes variable also and to add one to it once 'seconds' is > 59. but I'm not sure exactly how to go about this
Upvotes: 0
Views: 153
Reputation: 19252
You know that a minute is 60 seconds, so you could just count seconds and use the modulus operator %
seconds = 0
for timer in range(1,301):
#whatever ...
seconds += 1
print seconds/60, seconds % 60
Upvotes: 2