硬币抛掷猜测游戏

#硬币抛掷猜测游戏
import random
guess = ''
while guess not in ('heads', 'tails'):
    print('Guess the coin toss! Enter heads or tails:')
    guess = input()

#随机0和1
toss = random.randint(0, 1) # 0 is tails, 1 is heads
#关联字符串的随机性
#将整数0和1 + 正反面字符创建一个字典
dicts = {0:'tails', 1:'heads'}

if dicts[toss] == guess:
    print('You got it!')
else:
    print('Nope! Guess again!')
    guess = input()
    if dicts[toss] == guess:
        print('You got it!')
    else:
        print('Nope. You are really bad at this game.')

猜你喜欢

转载自www.cnblogs.com/ekin/p/9462718.html