Need help with coding a function in Python
devers.meetthebadger.jason at gmail.com
devers.meetthebadger.jason at gmail.com
Mon Oct 31 18:09:11 EDT 2016
http://imgur.com/a/rfGhK#iVLQKSW
How do I code a function that returns a list of the first n elements of the sequence defined in the link? I have no idea!!!!!
So far this is my best shot at it (the problem with it is that the n that i'm subtracting or adding in the if/else part does not represent the element's position, but just the n that I am plugging into the function):
def reca(n):
rlist=[0]
while len(rlist) < n:
if (rlist[-1]-n) > 0 and (rlist[-1]-n) not in rlist:
rlist.append(rlist[-1]-n)
else:
rlist.append(rlist[-1]+n)
return(rlist)
More information about the Python-list
mailing list