有兩個問題。首先是打印員工。你在做什麼是打印整個陣列而不是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(記錄)。 –