【问题标题】:How to implement switch case in python using Dict如何使用 Dict 在 python 中实现 switch case
【发布时间】:2022-06-14 13:30:11
【问题描述】:

我正在尝试使用 dict 实现 switch case,但该函数无法调用。所以如果选择 1 将如何调用 addEmployee() 方法,则如下代码所示。

  employee_dictionary = {}       
  while proceed:

       print('\n Employee Management System\n')
       print('\t1. Add a new employee')
       print('\t2. Delete an existing employee')
       print('\t3. Save and Quit\n')
       option_choice = int(input('Enter an option to continue: '))

       # Map each choice to the functions below using a dictionary
       options = {
           1:"addEmployeeInDict",
           2:"DeleteEmployee",
           3:"Exit"
       }
       proceed = options[option_choice](employee_dictionary)

【问题讨论】:

  • 添加员工代码:代码可以在不使用开关的情况下正常工作

标签: python python-3.x


猜你喜欢
  • 2019-11-18
  • 1970-01-01
  • 2017-07-21
  • 1970-01-01
  • 2019-04-07
  • 1970-01-01
  • 1970-01-01
  • 2016-11-25
  • 2014-07-26
相关资源
最近更新 更多