#1
  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. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    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"
    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
  4. #3
  5. 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.
  6. #4
  7. 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
  8. #5
  9. 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

IMN logo majestic logo threadwatch logo seochat tools logo