课后作业 day07

Python 实战练习 day07

猜年龄

# 猜年龄游戏
# 1.给定年龄,用户可以猜三次年龄
# 2.年龄猜对,让用户选择两次奖励
# 3.用户选择两次奖励后可以退出
age = 18
count = 0
gift_list = []
i = 0
a,b,c = '手机','电脑','ipad'
while i < 3:
    get_age = int(input('请输入年龄:'))
    if get_age > age:
        print('猜大了')
    if get_age < age:
        print('猜小了')
    else:
        print('恭喜你,猜对了!')
        while count < 2:
            gift = input('''请礼物对应的数字,挑选你的礼物,一共可以挑选两次
    'a':手机,'b':电脑,'c':ipad
    退出请按'N'或'n': ''')
            if gift == 'a' :
                count += 1
                gift_list.append(f'{a}')
            elif gift == 'b':
                count += 1
                gift_list.append(f'{a}')
            elif gift == 'c':
                count += 1
                gift_list.append(f'{c}')
            elif gift == ('N' or 'n'):
                break
            else:
                print('输入的为无效字符,请重新输入')
    if count != 0:
        break
    i += 1
if count != 0:
    print('恭喜你获得:',gift_list)
原文地址:https://www.cnblogs.com/samoo/p/11515191.html