My solution for Heads and Tails coin Program
def coingame(num):
"""We are taking 1 as head and 0 as tail for easy calculation """
coins = []
for i in range(num): # This function autogenerate list where we think 1 as Head and 0 as Tail
coins.append(1)
for i in range(len(coins)): # This two for loop statement flip coins as we needed
for j in range(i + 1, len(coins), i + 2):
if coins[j] == 1:
coins[j] = 0
else:
coins[j] = 1
print(sum(coins)) # print the sum of coins List using Sum function
coingame(10)
0 answers ( 0 marked as helpful)