Posted on:

29 Jun 2022

1

My solution for the Coins challenge

def coins(n):
    coins_tail ="Tail"
    coins_head = "Head"
    coins_liste = ["Head" for i in range (n)]
    print(coins_liste)
    start = 1
    step = 2
    while start < len(coins_liste):
        finish = False
        check_liste = [ ]
        for i in range(start, len(coins_liste), step):
            check_liste.append(i)
        for j in check_liste:
            if coins_liste[j] == coins_tail:
                coins_liste[j] = coins_head
            else:
                coins_liste[j] = coins_tail
        start += 1
        step += 1

        #print(check_liste)
    print(coins_liste)
    result_liste = []
    for k in range(len(coins_liste)):
        if coins_liste[k] == coins_head:
            result_liste.append(k+1)
        else:
            result_liste = result_liste
    print(result_liste)
coins(10)


['Head', 'Head', 'Head', 'Head', 'Head', 'Head', 'Head', 'Head', 'Head', 'Head']
['Head', 'Tail', 'Tail', 'Head', 'Tail', 'Tail', 'Tail', 'Tail', 'Head', 'Tail']
[1, 4, 9]
0 answers ( 0 marked as helpful)

Submit an answer