User selection, calling the method of writing the corresponding function

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.