View Full Version : python - count up,then down while inside range

01 January 2012, 05:56 PM
I have a range of x amount and i want to count up to 10, then back to 1, then back to 10 over and over trough out the range until x is reached.

Iv tried a bunch of stuff but cant seem to get it right.

i was thinking something like once this number is reached (10) now run this code i-=1 untill
1 is reached then run this i+=1 and it would just cycle though this until the end.

01 January 2012, 03:39 PM
you could try this
x = 2
ran = range(10)

for i in range(x):
for j in ran:
print "%d - %d" %(i, j)
for k in ran:
print "%d - %d" %(i, k)

01 January 2012, 10:11 PM
After some messing around i ended up on this..

# Up then Down...ex
x = [] #empy list
for i in range(1,11): # range of cycle -10
z = 0 # variale counter for range
for i in range(1,101): # cycle length
if z == len(x)-1:
z = 0 # re-set counter
z += 1

CGTalk Moderation
01 January 2012, 10:11 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.