|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
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"
__________________
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 Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month |
|
#3
|
|||
|
|||
|
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
|
|||
|
|||
|
Doh, Scorp got to it while I was typing
![]() |
|
#5
|
|||
|
|||
|
LOL! thank you
![]() I knew it would be somthing really simple |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > counting += numbers |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|