【发布时间】:2021-08-25 23:41:56
【问题描述】:
我被卡住了,我不确定我错过了哪一部分课程......一旦用户输入“完成”,我怎样才能让我的脚本结束循环?我还有更多功能要添加,因此可以通过 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"'))
【问题讨论】:
-
if name == 'done': break -
我一定是做错了什么,当我输入它并没有中断
-
中断不会中断输入,它会在字符串中继续。
-
我做到了!它需要在用户输入的那部分末尾!不是在整个动作结束时!
-
确实……这就是它需要的地方(
employee_list.append()需要成为for循环的一部分)
标签: python list search return edit