10.8调试硬币抛掷

原来的代码

import random
guess = ''
while guess not in ('heads','tails'):
    print('Guess the coin toss! Enter heads or tails:')
    guess = input()
toss =  random.randint(0, 1)  # 0 is tails, 1 is heads
toss=['tails','heads'][toss]
if toss == guess:
    print('You got it!')
else:
    print('Nope! Guess again!')
    guess = input()
    if toss == guess:
        print('You got it!')
    else:
        print('Nope. You are really bad at this game.')

图片是原来的代码,下面的是修改后的代码,原来的代码主要有2错误。1是toss是数字,而输入是字符串,永远都无法相等。
2是第二次输入时变量错写为guesss,正确应该为guess

猜你喜欢

转载自blog.csdn.net/qq_40012965/article/details/81301632
今日推荐