【发布时间】: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