Jul-24-2017, 11:03 AM
(This post was last modified: Jul-24-2017, 11:58 AM by juniorcoder.)
Hello everybody ,
I am trying to make a list by alternating two values but I am getting error. Basically my list should be like if it starts with 2 should go on 3 like [2 3 2 3 2] or if it starts with 3 should go on [3 2 3 2 3] . I coded as below but I am getting the "list assignment index out of range" error. I am very beginner in python and I would be very happy if you can help me ;
Thank you in advance
Regards
I solved it :)
I am trying to make a list by alternating two values but I am getting error. Basically my list should be like if it starts with 2 should go on 3 like [2 3 2 3 2] or if it starts with 3 should go on [3 2 3 2 3] . I coded as below but I am getting the "list assignment index out of range" error. I am very beginner in python and I would be very happy if you can help me ;
Thank you in advance
Regards
tm=[2,3] L=[] for i in range(5): number=(random.choice(tm)) L.append(number) if(L[i]==2): L[i+1]=3 else: L[i+1]=2
I solved it :)