十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊
量身定制 + 運(yùn)營維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
python實現(xiàn)二級登陸菜單的代碼如下所示:
""" 1.三級菜單 注冊 登陸 注銷 2.進(jìn)入每一個一級菜單,都會有下一級的菜單 """ user_item = dict() try: while True: print('-------Welcome sir-------') input_choice = int(input('Please enter your choice:1:Registration 2:login 3:logout:')) # 用戶輸入自己的選擇,會進(jìn)入到相關(guān)的二級菜單 if input_choice == 1: # if input_choice==1 進(jìn)入注冊 user = input('Please enter your account number:') pwd = input('please enter your password:') # 保存用戶注冊的賬號 user_item['user'] = user user_item['pwd'] = pwd # 提示用戶注冊成功 print('您的賬號已生效,下次請用該賬號:{}登陸本系統(tǒng)'.format(user)) # if input_choice==2 進(jìn)入登陸 elif input_choice == 2: login_user = input('Please enter your login account number:') login_pwd = input('please enter your login password:') # 對用戶輸入的賬號和密碼進(jìn)行確認(rèn) if login_user == user_item['user'] and login_pwd == user_item['pwd']: print('Welcome sir:{}'.format(login_user)) else: print('Sorry, your account or password is incorrect. Please confirm and come back') # if input_choice == 3 進(jìn)入注銷 elif input_choice == 3: logout_input = input('Do you really want to quit this system?,y or n') if logout_input == 'y': break elif logout_input == 'n': input_choice = int(input('Please enter your choice:1:Registration 2:login 3:logout:')) else: print('Your input is incorrect') except Exception as re: print(re) finally: print('')