有两个问题。首先是打印员工。你在做什么是打印整个阵列而不是for
循环的项目。
第二个问题是,每次选择“1”时都会重新创建record
。你可能应该把它放在while
循环之前。
我也修正了身份。我希望现在好一点。
例如:
select=True
record=[]
while select:
print ("""
Personnel Database
1. Add a new employee
2. Display all employees
3. Search for an employee
4. View full-time employees
5. View part-time employees
6. View number of employee records in database
7. Delete an employee from the database
8. Exit
Choose an option (1-7) or 8 to Exit
""")
select=input("What would you like to do? ")
if select == "1":
print("Add a new employee")
enterName = input ("Enter employee name:")
enterTitle = input ("Enter employee Job title:")
enterRate = float (input ("Enter employee hourly rate:£"))
enterService = float(input ("Enter number of years service:"))
fulltime = input ("Is the employee full-time? Y/N:")
if fulltime.capitalize == "Y":
break
elif fulltime == "N":
break
record.append((enterName, enterTitle, enterRate, enterService, fulltime))
print ("The employee you have entered is:",record)
if select == "2":
print ("Displaying all employees")
print ("Employee names:")
for r in record:
print(r[0])
的第二个问题是因为每次你选择的时间“1”的名单'record'被重建。如果你把它放在'while'之前,我想你可以解决它。 – gabra
它是什么输出? – gabra
另外,在最后一个循环中,你应该“打印(记录)”。我建议将列表的名称改为'records',这样你就可以在记录中进行记录,最后进行print(记录)。 –