[Python] Heads or Tails / Coin-flip program

Discussão em 'Python' iniciado por Stack, Outubro 5, 2024.

  1. Stack

    Stack Membro Participativo

    I want to write a coin flip or "Heads or Tails" program, but when I run it, it only gets either heads or tails everytime. I can't see why, it's a logical error so I find it hard to spot.

    import random

    flips = 1

    coin = random.randint(1,2)

    heads = 0
    tails= 0

    while flips <= 100:
    if coin == 1:
    print("Heads")
    heads += 1
    flips +=1
    elif coin == 2:
    print("tails")
    tails += 1
    flips +=1

    print("You got", heads, "heads and", tails,"tails!")


    input("Exit")

    Continue reading...

Compartilhe esta Página