I'm struggling with some project work and thought someone may be able to help me here. I am writing a database tool, and need to be able to find an ID value from a person on a csv file, and edit their employee status from active to inactive. Having very basic python knowledge, I am struggling with this. Here is my code that is working now.
def menu():
print("Welcome to the Employee database\n")
print("1. Add a new employee\n")
print("2. Remove an existing employee\n")
print("3. Change/modify the details of an existing employee\n")
print("4. Search and display the details for a particular employee\n")
print("0. Quit\n")
choice = int(input("Please select an option using the numbers above"))
if choice == 0:
return
if choice == 1:
add()
if choice == 2:
remove()
if choice == 3:
change()
if choice == 4:
search()
def add():
print("Adding a new employee, please enter the following details\n")
employee_id = int(input("Enter your employee ID\n"))
name = input("Enter your name\n")
department = input("Enter your department\n")
designation = input("Enter your designation\n")
joining_date = input("Enter your starting date [DD/MM/YYYY]\n")
employee_status = input("Enter the employee status [Active/Inactive]\n")
with open('database.csv', "a") as f:
employee_info = ""
employee_info += "%s," % employee_id
employee_info += "%s," % name
employee_info += "%s," % department
employee_info += "%s," % designation
employee_info += "%s," % joining_date
employee_info += "%s," % employee_status
employee_info += "\n"
f.write(employee_info)
menu()
I need it to be able to take an input from the user of the ID they want to make inactive, find the right person in the csv and change their tag to inactive. Is this possible?
I would appreciate any help whatsoever!
Edit:
Here is the csv
file contents:
Employee ID,Name,Department,Designation,Joining Date,Employee Status
456,Matt,IT,Data,02/04/2018,Active
245,John,HR,Manager,30/04/2019,Active