zoukankan      html  css  js  c++  java
  • 2019.9.19登陆注册猜数字给奖品combo

    #注册函数
    def register():
        registor_count = 0
    
        while registor_count < 3:
            username_inp = input('user name:')
            userpwd_inp = input('user password:')
            re_userpwd_inp = input('password again:')
            if userpwd_inp == re_userpwd_inp:
                with open('user_info.txt','a',encoding = 'utf8') as fa:
                    fa.write(f'{username_inp}:{userpwd_inp}
    ')
                print('registor successfully')
                break
            else:
                registor_count += 1
                print('different password')
                continue
    
    
    
    
    #登录
    # login_count = 0
    # while login_count < 3:
    #     username_inp = input('user name:')
    #     userpwd_inp = input('user password:')
    #
    #     with open('user_info.txt','r',encoding='utf8') as fr:
    #         for user_info in fr:
    #             user_name,user_pwd =user_info.split(':')
    #             if user_name.strip() == username_inp :
    #                 if user_pwd.strip() == user_inp:
    #                     print('login successfully')
    #                     break
    #                 else:
    #                     print('error password')
    #                     login_count += 1
    #                     if login_count == 3:
    #                         print('error too many times')
    #                         break
    #         else:
    #             print('unfound username')
    # #登录
    def login():
        username_inp = input('user name:')
        userpwd_inp = input('user password:')
    
        with open('user_info.txt','r',encoding='utf8') as fr:
            for user_info in fr:
                user_name,user_pwd =user_info.split(':')
                if (user_name.strip() == username_inp and user_pwd.strip() == userpwd_inp):
                    print('login successfully')
                    break
            else:
                print('login is failure')
    
    #猜年龄
    
    def guess_age():
        age = 30
        guess_count = 0
        while guess_count < 3:
            guess_age = int(input('guess the age:'))
            guess_count += 1
            if guess_age > age:
                print('too old')
            elif guess_age < age:
                print('too young')
            else:
                print('bingo')
                break
        else:
            print('too many errors')
    
    
    #选择奖品
    def prize():
        prize_dict = {
            '1':'apple',
            '2':'orange',
            '3':'banana',
            '4':'pear'
        }
        print(prize_dict)
        prize_choice = input('choose a prize:')
        if prize_choice in prize_dict:
            print(f"you got one {prize_dict.get(prize_choice)}")
        else:
            print('wrong number')
    
    
    
    def combo():
        while True:
            get_inp = input('registor press 1,login press 2,q to quit:')
            if get_inp == '1':
                register()
                login()
                guess_age()
                prize()
            elif get_inp == '2':
                login()
                guess_age()
                prize()
            elif get_inp == 'q':
                break
            else:
                print('again')
                continue
    
    
    combo()
    
    
  • 相关阅读:
    面试时面试官想要听到什么答案(关于一些vue的问题)
    Redis主从复制以及主从复制原理
    当面试官问你:如何进行性能优化?
    swoole通往大神之路——swoole任务中心说明及进程任务架构搭建
    全局句柄表
    句柄表(私有句柄表)
    关于VAD的两种内存隐藏方式
    通过修改VAD属性破除锁页机制
    R3环申请内存时页面保护与_MMVAD_FLAGS.Protection位的对应关系
    利用内存锁定技术防止CE修改
  • 原文地址:https://www.cnblogs.com/agsol/p/11550674.html
Copyright © 2011-2022 走看看