1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Apr 2004
Posts
2
Rep Power
0

#### 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...

stumped
thanks for looking
2. Use a second variable and increment it each time you reset the number to 0.
Code:
```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"```
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Aug 2003
Posts
217
Rep Power
0
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.
4. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Aug 2003
Posts
217
Rep Power
0
Doh, Scorp got to it while I was typing
5. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Apr 2004
Posts
2
Rep Power
0
LOL! thank you
I knew it would be somthing really simple