Apr-02-2019, 12:20 AM
Hello everyone,
I have been learning Python for a few weeks now and I am now doing a project to create a employee management system. I got to the point of creating a branching path for the user to either select 1 to add employee or 2 to view the list of employees. The problem is after I select 1 and add one employee the program stops... I want it to go back to the screen where it asks "1 or 2" so it can ask for user input every time the user adds or views the lists. I don't want it to end... I have been looking and looking for hours at different videos of creating loops etc and I either get a syntax error or some crazy non stop printing that I cant stop unless I kill the program...
My code is:
I have been learning Python for a few weeks now and I am now doing a project to create a employee management system. I got to the point of creating a branching path for the user to either select 1 to add employee or 2 to view the list of employees. The problem is after I select 1 and add one employee the program stops... I want it to go back to the screen where it asks "1 or 2" so it can ask for user input every time the user adds or views the lists. I don't want it to end... I have been looking and looking for hours at different videos of creating loops etc and I either get a syntax error or some crazy non stop printing that I cant stop unless I kill the program...
My code is:
counter = 0 def main(): global counter print("Employee Management System\n--------------------------------------") print("There are", main(), "employees in the system.") print("\n") print("Please select from the following options:") #----------------#1 function to add employee----------------------------- employees =[] names = [] def add_em(): name = input('Employee Name:') ssn = input('Employee SSN:') phone = input('Employee Phone No.:') email = input('Employee Email:') salary = input('Employee Salary: $') line = (name + ssn + phone + email + salary) names.insert(counter, name) employees.insert(counter,line) counter =counter+1 #-----------------#2 function to view the list---------------------------- def view_em(): if not names: print("Sorry there are no employees in the list") else: print(counter,names) #----------------- Asks user for option 1 or 2 ---------------------------- a = input("Press 1: Add an employee \nPress 2: View employee list\nInput: ") if a == "1": add_em() elif a == "2": view_em() # How do I make this loop back to "a = input..." so the user can choose again # between 1 or 2...?