python - 创建员工数据库时如何停止循环?
问题描述
我被卡住了,我不确定我错过了哪一部分课程......一旦用户输入“完成”,我怎样才能让我的脚本结束循环?我还有更多功能要添加,因此可以通过 SSN 进行搜索并返回格式化结果。我感到很失落!
counter = len(employee_list)
#view all employees, enter employees, Search by SSN. Format as directed.
employee_list = []
for i in range(10):
print('Please enter information for employee ' + str(i + 1) + ':')
name = input('Enter employee first and last name, if finished type done:')
ssn = input('Enter SSN: ')
phone = input('Enter phone number: ')
email = input('Enter email: ')
salary = input('Enter salary: ')
employee_list.append([name,ssn,phone,email,salary])
index = int(input('Which action would you like to take next? Type "VIEW ALL", "SEARCH", OR
"EXIT"'))
解决方案
尝试这个:
#view all employees, enter employees, Search by SSN. Format as directed.
employee_list = []
for i in range(10):
print('Please enter information for employee ' + str(i + 1) + ':')
name = input('Enter employee first and last name, if finished type done:')
if name == "done":
break
ssn = input('Enter SSN: ')
if ssn == "done":
break
phone = input('Enter phone number: ')
if phone == "done":
break
email = input('Enter email: ')
if email == "done":
break
salary = input('Enter salary: ')
if salary == "done":
break
employee_list.append([name,ssn,phone,email,salary])
index = int(input('Which action would you like to take next? Type "VIEW ALL", "SEARCH", OR "EXIT"'))
推荐阅读
- tensorflow - 如何从其他脚本运行 tensorflow retrain.py?
- c# - 如何获取 col 和 row 的值?
- fedora - Mendeley 桌面无法在 Fedora 31 中打开
- php - PHP表单验证红色错误未显示在框周围
- python - 你如何从两列对组成一个方阵?
- python - 在 Python 中将 datetime.date 转换为 pandas.core.series.Series?
- javascript - 如果路由有两个“/”符号,为什么 Bootstrap 会停止工作
- wordpress - Wordpress –– 有人使用我的管理员电子邮件地址/用户名发送电子邮件确认虚构注册
- javascript - 带有查询字符串的快速路由
- react-native - React Native 状态管理问题 - useState 钩子何时加载?