猜年龄v2.0

'''
用户登录,只有三次机会

给定年龄,用户可以猜三次年龄

年龄猜对,让用户选择两次奖励,输入无效字符,让其选择要不要礼物

用户选择两次奖励后可以退出,选择第一次后提示还有一次
'''
#基本信息定义
user_info_dict = {
    'james':'007',
    'thor':'001',
    'ironman':'002',
    'spiderman':'003'
}
prize_dict = {'0': 'durex', '1': 'okamoto', '2': 'Jissbon'}
login_count = 0
guess_count = 0
age = 30

#用户名密码输入
while 1:
    user_name = input("login the user'name:")
    user_pwd = input("login the password:")
    if login_count == 2:
        print('error too many times.')
        break

    if (user_name in user_info_dict) and (user_info_dict.get(user_name) == user_pwd):
        print('start\n')
        break
    else:
        login_count += 1
        print('name or password error')
        continue




while guess_count < 3:
    # 输入数字才能加入猜数字
    while 1:
        guess_age = input('guess my age:'.strip().lstrip('0'))
        if guess_age.isdigit():
            break
        else:
            print('fucking number please!')

    guess_age_int = int(guess_age)
    guess_count += 1

    # 核心判断
    if guess_age_int > age:
        print('too old')
    elif guess_age_int < age:
        print('too young')
    else :
        print('bingo')
        print(prize_dict)
        prize_count = 0

        #选择奖励
        while prize_count < 2:
            prize_select = input('select a prize:')
            prize_count += 1
            if prize_select in prize_dict:
                print(f'you got a {prize_dict[prize_select]}')
            else:
                print('want to give up the prize?')
                choice = input('yes or no:')
                if choice == 'no':
                    prize_count = 0
                    continue
                else:
                    break
            print('one more prize')
        break






posted @ 2019-09-16 20:17  Agsol  阅读(91)  评论(0编辑  收藏  举报