猜年龄游戏
count = 0 # 定义次数
age = 20 # 定义年龄
prize = {0: "玩具汽车", 1: '变形金刚', 2: '气球', 3: '充气娃娃'}    # 定义奖品
hengxian = ("*" * 20)   # 横线
print(f"{hengxian}让我们开始游戏吧{hengxian}")
while count < 3:
get_age = input("请输入你的年龄>>>>")
if not get_age.isdigit():        # 判断是否捣乱
print("请输入数字!")
continue
get_age_int = int(get_age)
if get_age_int == age:
    print("恭喜你猜中了")
    print(f"这是您的奖品:{prize}")
    for i in range(2):
        prize_option = input("请通过数字选择您的奖品,如不需要则按n退出")
        if prize_option != 'n':
            print(f"恭喜您获得奖品:{prize[int(prize_option)]}")
        else:
            break
    break
elif get_age_int > age:
    print("你猜大了")
if get_age_int < age:
    print("你猜小了")
    count += 1  # 成功玩了一次游戏
    #         判断是否超过三次
    if count != 3:
        continue
    again_ganme = input("是否需要重新游戏,重新则按y")
    if again_ganme == 'y':
        count = 0
让我们开始游戏吧
请输入你的年龄>>>>20
恭喜你猜中了
这是您的奖品:{0: '玩具汽车', 1: '变形金刚', 2: '气球', 3: '充气娃娃'}
请通过数字选择您的奖品,如不需要则按n退出0
恭喜您获得奖品:玩具汽车
请通过数字选择您的奖品,如不需要则按n退出3
恭喜您获得奖品:充气娃娃
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号