Reputation: 65
if select == '2':
print('Displaying all employees\n')
print('Employee names:\n')
for records in record:
print(record[0])
My 1st option works perfectly fine, however my 2nd optiond doesn't print out the "enterName" from the list. How do I fix this? I tried to find answer but I couldn't find one specific enough.
Thanks for looking, and helping me :).
Also, another problem I have is that when trying to add more than one "new employee" it overwrites the first one, how can I work around this?
Upvotes: 3
Views: 133
Reputation: 10554
There are tow issues. The first is printing the employees. What are you doing is printing the full array and not the items of the for
loop.
The second issue is that record
is being recreated every time you select "1". You probably should put it before the while
loop.
I also fixed the identation. I hope it is better now.
For example:
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])
Upvotes: 1