User selection, call the corresponding function writing method:
1. First, the menu is exported, so the user can select it.
2. Create a menu dictionary k= ordinal, v= operation function
3. Call the function of the corresponding ordinal selected by the User: Menu[option] (parameter)
def account_info (acc_data): Print (User_data) def repay (Acc_data): Passdef Withdraw (acc_data): Passdef Transfer (ACC _data): Passdef Pay_check (acc_data): Passdef logout (acc_data): Passdef Interactive (Acc_data): # # # Note Menu "" "..." "The content under" ' Interact with User:return: 'menu = u "-------oldboy Bank---------\033[32;1m1. Account Information 2. Repayment (function has been realized) 3. Withdrawal (function achieved) 4. Transfer 5. Bill 6. Exit \033[0m ' menu_dic = {' 1 ': Account_info, ' 2 ': Repay, ' 3 ': Withdraw, ' 4 ': transfer, ' 5 ': Pay_check, ' 6 ': logout,} Exit_flag = False while not exit_flag:print (menu) use R_option = input (">>:"). Strip () if user_option in Menu_dic: #判断用户的输 into whether in the dictionary menu_dic[user_option] (acc_data) #menu_dic [user_option] equivalent to a function func, and then Func (Acco_data) with parentheses, passed in the parameter
else: print ("\033[31;1moption does not exist!\033[0m") def Run (): "This function would be the called right A- When the program started, here handles the user interaction stuff : return: ' acc_data = auth.acc_login (user _data,access_logger) if user_data[' is_authenticated ': user_data[' account_data '] = Acc_data Interactive (User_data)
User selection, calling the method of writing the corresponding function