mardi 7 février 2017

The 'while loop' does not seem to be working for my program

I am trying to play a game of rolling two dice. I am trying to print the final result 20 times, however the 'while loop' does not seem to be working, where am I going wrong?

coin_one = [random.randint(0, 1) for x in range(500)]
coin_two = [random.randint(0, 1) for x in range(500)]
game = zip(coin_one, coin_two)

def coin_toss_game1():    
    total = 0
    for a, b in game:
        if a and b:
            total += 1
        elif not a and not b:
            total -= 1
        else:
            continue
    return total

y = 0
while y < 20:
print(coin_toss_game1())
y += 1

This is giving a result of: 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Its supposed to return a result of something like: 7 2 -5 15 -9 12 ... what mistake am I making here?




Aucun commentaire:

Enregistrer un commentaire