• 练习——循环2


    一、猜年龄

    age = 18
    x = 3
    prize_dict ={
        '1': '女朋友',
        '2': 'ps4pro',
        '3': 's9世界赛决赛门票',
        '4': '霍格沃兹入学通知书',
        '5': '哆啦A梦',
        '6': '皮卡丘',
        '7': '核弹发射按钮',
        '8': '潘多拉魔盒',
        '9': '死亡笔记',
        '10': '幻想乡永久居住证'
    }
    while x > 0:
        guess = input('猜猜我的年龄>>> ').strip()
        if not guess.isdigit():
            print('好好说个数字啦!')
            continue
        guess = int(guess)
        if guess > age:
            if x != 1:
                x -= 1
                print(f'猜大啦!你还有{x}次机会!')
                while True:
                    answer = input('想继续玩吗?回复Y可以继续,回复N就直接退出啦!').lower()
                    if answer == 'y':
                        break
                    elif answer == 'n':
                        print('下次再来玩哦,再见啦!')
                        x = 0
                        break
                    else:
                        print('别乱回复鸭!')
                        print('输入Y或者N就行啦!')
                continue
            print('还是猜大啦!没机会咯!拜拜~~')
            break
        elif guess < age:
            if x != 1:
                x -= 1
                print(f'猜小啦!你还有{x}次机会!')
                while True:
                    answer = input('想继续玩吗?回复Y可以继续,回复N就直接退出啦!').lower()
                    if answer == 'y':
                        break
                    elif answer == 'n':
                        print('下次再来玩哦!再见啦!')
                        x = 0
                        break
                    else:
                        print('别乱回复鸭!')
                        print('输入Y或者N就行啦!')
                continue
            print('还是猜小啦!没机会咯!拜拜~')
            break
        else:
            if x == 3:
                print('好厉害啊,一次就猜对啦!')
            elif x == 2:
                print('恭喜你!猜对啦!')
            else:
                print('终于猜对啦!')
            a = None
            for i in range(2):
                show = prize_dict.items()
                for k, v in show:
                    print(k, v)
                if i == 0:
                    while True:
                        choice_1 = input('选择一份奖品吧!不要的话也可以输入‘N’退出哦!').lower()
                        if choice_1 == 'n':
                            print('呜呜呜~~一件喜欢的都没有吗?')
                            a = 1
                            break
                        if not choice_1 in prize_dict:
                            print('别乱输入鸭!')
                            print('输入奖品对应的数字就行啦!')
                            continue
                        prize1 = prize_dict[choice_1]
                        print(f'你的第一件奖品就是 {prize1} 啦!呐,请收好。')
                        prize_dict.pop(choice_1)
                        break
                    if a:
                        break
                choice_2 = input('还能再选择一件哦,不想要了就输入‘N’吧。').lower()
                if choice_2 == 'n':
                    print('那就只要一件咯。')
                    break
                if not choice_2 in prize_dict:
                    print('别乱输入鸭!')
                    print('输入奖品对应的数字就行啦!')
                    continue
                prize2 = prize_dict[choice_2]
                print(f'你的第二件奖品就是 {prize2} 啦,请收好哦')
                break
            print('游戏结束啦!下次再来玩吧!')
            break
    
  • 相关阅读:
    ROXFiler 2.6
    ubuntu下lxr的运用
    NTFS3G-Linux 的 NTFS 驱动步骤
    Songbird 0.2.5 Final
    ePDFView:一个轻量的 PDF 文档阅读东西
    Gmail Notifier:又一个 Gmail 邮件通知法式
    Hybrid Share-文件分享软件
    Dolphin:KDE 中的文件管理器
    文泉驿点阵宋体 0.8(嬴政)正式公布
    KDE 4 Kludge 发布宣布
  • 原文地址:https://www.cnblogs.com/binyuanxiang/p/11515142.html
Copyright © 2020-2023  润新知