April 9th, 2004, 12:52 PM
counting += numbers
Hey everyone this is my first post here
its a simple problem and i'll most likely figure it out sooner or later
lets say I am incrementing a number between 1 and 30
when it the increment reaches 30 it starts back a 0
my question is how would I go about counting the number of times the incremented number reaches 30...
thanks for looking
April 9th, 2004, 01:44 PM
Use a second variable and increment it each time you reset the number to 0.
counter = number = 0
for loop in range(0, 500):
number += 1
# Check if number has reached 30
# and if so, reset it and increment counter
if number == 30:
number = 0
counter += 1
print "We cycled ", counter, "times"
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
"I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
April 9th, 2004, 01:46 PM
Well, lets assume your looping, and it each interation increments the variable 'X'. You could do an if test for each iteration that tests whether the variable 'X' is at 30 or not. If so, it could reset 'X' to 0 and increment a second variable by 1 (lets call it 'count'). Whenever you stop looping, 'count' would contain the number of times 'X' reached 30.
April 9th, 2004, 01:47 PM
Doh, Scorp got to it while I was typing
April 9th, 2004, 02:46 PM
LOL! thank you
I knew it would be somthing really simple