【发布时间】:2021-03-08 10:46:37
【问题描述】:
empmangpro = True
employees = []
while empmangpro == True:
try:
empcount = len(employees)
print("--------------------Employee Management System--------------------")
print("")
print("There are "+str(empcount)+" employees in the system.")
print("")
print("------------------------------------------------------------------")
print("1. Add new employee")
print("2. View all employees")
programselection = int(input("Please select your option number: "))
if programselection == 1:
employee = []
employee.append(input("First and Last Name: "))
employee.append(input("Social Security Number: "))
employee.append(input("Phone Number: "))
employee.append(input("Email Address: "))
employee.append(input("Salary:$"))
employees.append(employee)
elif programselection == 2:
i = 0
j = 0
empstr = ""
while i < int(empcount):
while j < 5:
empstr = empstr + employees[i][j]
if j != 4:
empstr = empstr + ", "
j += 1
if i+1 != int(empcount):
empstr = empstr + "\n"
j = 0
i += 1
print(empstr)
print[employees]
elif programselection < 3:
empmangpro = False
else:
print("Please enter valid information")
except ValueError:
print("Please enter valid information")
continue
我有选项 1,您可以将多个员工添加到系统中,但是当我选择选项 2 时,没有任何反应。它应该打印我添加的所有员工。我在这里做错了什么?我编程才不到一个月,所以我还有很多东西要学。我错过了什么或做错了什么?
【问题讨论】:
-
在您的
if programselection == 1:之后,您是否缩进下一行?现在看来没有。elif也应与if处于同一级别。 -
我在发布此内容时弄乱了间距我没有收到错误或任何内容,只是当我选择选项 2 时没有任何反应,它只是空白
-
您要求我们用一种可以改变程序控制的语言(例如 python)来调试您的间距不正确的代码。我们怎么知道它是复制意大利面还是实际问题(隐藏)。
-
嘿@Corey 对不起,如果我觉得我很粗鲁。我想帮助你,并要求你努力正确地格式化你的代码块。
-
没关系,我想我现在得到了正确的间距?
标签: python loops error-handling