day10 作业

作业

1.在猜年龄的基础上编写登录、注册方法,并且把猜年龄游戏分函数处理,如

  1. 登录函数
  2. 注册函数
  3. 猜年龄函数
  4. 选择奖品函数
def login():
    """登录"""
    username_inp = input('请输入你的用户名:')
    pwd_inp = input('请输入你的密码:')

    with open('user_info.txt', 'r', encoding='utf8')as fr:
        for user_info in fr:
            username_pwd = user_info.split(':')

            if username_strip() == username_inp and pwd_strip() == pwd_inp:
                print('登录成功')
            else:
                print('登录失败')
def register():
    """注册"""
    count = 0
    while count < 3:
        username_inp = input('请输入你的用户名:')
        pwd_inp = input('请输入你的密码:')
        re_pwd_inp = input('请再次输入你的密码:')

        if not pwd_inp==re_pwd_inp:
            print('两次输入的密码不一致')
            count += 1
            continue

        with open('user_info.txt', 'a', encoding='utf8')as fa:
            fa.write(f'{username_inp}:{pwd_inp}\n')
            fa.flush()
            break
def guess_age():
    '''猜年龄'''
    age_count = 0
    while age_count < 3:

        age_inp = input('请输入你的年龄:')

        if not age_inp.isdigit():
            print('你活了b岁哟')
            continue

            age_inp_int = int(age_inp)

        if age_inp_int > age:
            print('猜大了')
        elif age_inp_int < age:
            print('猜小了')
        else:
            print('猜对了')
            break
def prize():
    '''选择奖品'''

    prize_dic = {
        '1': 'watchdog3',
        '2': 'FIFA20',
        '3': 'BATTLEFIELD V',
        '4': 'Medal of Honor: Warfighter',
        '5': 'Plants VS Zombies',
        '6': 'Tom Clancys Ghost Recon: Breakpoint'
    }

    prize_msg='''
        1 watchdog3
        2 FIFA20
        3 BATTLEFIELD V
        4 Medal of Honor: Warfighter
        5 Plants VS Zombies
        6 Tom Clancys Ghost Recon: Breakpoint

    '''
    prize_count = 0
    get_prize_dict = {}
    while prize_count < 2:
        print('奖品如下', prize_msg)

        prize_choice = input('请输入你想要的奖品:')
        prize = prize_dict[prize_choice]

        if prize in get_prize_dict:
            get_prize_dict[prize] += 1
        else:
            get_prize_dict[prize] = 1

        print(f'恭喜你获得奖品{prize}')

        prize_count += 1

    print(f'总共获得奖品为:{get_prize_dict}')

猜你喜欢

转载自www.cnblogs.com/colacheng0930/p/11551590.html