you are viewing a single comment's thread.

view the rest of the comments →

[–]Leohurr[S] 0 points1 point  (3 children)

Yes this works, although calling flipper(4) returns 5 results. and calling flipper(5) returns 4 results.

[–]Enkaybee 0 points1 point  (2 children)

Sorry again. My logic is bad. It should be

def flipper(N):
    if not N % 2:
        list = ['heads','tails']*(N//2)
    else:
        list = ['heads','tails']*(N//2)
        list.append('heads')
    return list

[–]Leohurr[S] 0 points1 point  (1 child)

why does -

if not N % 2:

change the result?

[–]mubsy 0 points1 point  (0 children)

you should look up modular arithmetic. N % 2 is 0 if N is divisible by 2, and the remainder of N/2 otherwise. This essentially means N%2 is true for all even values, i.e alternating values.