PDA

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


cwisbg
01-02-2012, 04: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.

jaydru
01-03-2012, 02: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)
ran.reverse()
for k in ran:
print "%d - %d" %(i, k)
ran.reverse()

cwisbg
01-03-2012, 09: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
x.append(i)
z = 0 # variale counter for range
for i in range(1,101): # cycle length
if z == len(x)-1:
x.reverse()
z = 0 # re-set counter
z += 1

CGTalk Moderation
01-03-2012, 09: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.