3个人头后的抛硬币杀戮程序

2024-05-16 08:11:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试着用掷硬币的方式来做一个密码。我想打印出每一个抛硬币的结果,直到有3个直头。我认为我的代码应该是正确的,但它只是打印0。我认为我的while循环是错误的


import random

face = 0
total_heads = 0
total_tails = 0
count = 0
while face>=3:
    coin = random.randint(0, 1)
    if coin == 0:
        print("Heads\n")
        total_heads += 1
        count += 1
        face += 1
    elif coin == 1:
        print("Tails\n")
        total_tails += 1
        count += 1
        face == 0
print(total_tails)
print(total_heads)
print(count)
print(face)


Tags: 代码密码count错误方式硬币randomface