23-调试硬币抛掷程序
调试硬币抛掷程序
下面程序实现一个简单的硬币抛掷猜测游戏。玩家有两次猜测机会(这是一个简单的游戏)。但是程序中有一些bug,让程序运行几次,找出bug,使该程序能正确运行:
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
if toss == guess:
print('You got it!')
else:
print('Nope! Guess again!')
guesss = input()
if toss == guess:
print('You got it!')
else:
print('Nope. You are really bad at this game.')