Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Learning python, stuck on some code.
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:
counter = 0
def main():
    global counter
print("Employee Management System\n--------------------------------------")
print("There are", main(), "employees in the system.")
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)
counter =counter+1
#-----------------#2 function to view the list----------------------------    
def view_em():
    if not names:
        print("Sorry there are no employees in the list")
#----------------- Asks user for option 1 or 2 ----------------------------
a = input("Press 1: Add an employee \nPress 2: View employee list\nInput: ")
if a == "1":
elif a == "2":
# How do I make this loop back to "a = input..." so the user can choose again
# between 1 or 2...?
You want a while True: loop. Put lines 28-32 inside that. Then have a third option to quit. When that option is selected, use a break statement to get out of the loop.
Craig "Ichabod" O'Brien -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

(Apr-02-2019, 12:43 AM)ichabod801 Wrote: You want a while True: loop. Put lines 28-32 inside that. Then have a third option to quit. When that option is selected, use a break statement to get out of the loop.

Thank you so much, that worked so beautifully.
I was putting the while True: loop in the wrong space, I was adding it at the end of everything and it was giving me errors. I watched so many videos and tutorials, I was close but couldnt get it right.
Thanks again!!

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Can you help about my learning project Qusha 1 117 Jul-21-2019, 07:46 PM
Last Post: Yoriz
  Learning Python in a month MuhammadNauman 1 141 Jul-17-2019, 11:53 AM
Last Post: metulburr
  machine learning error (using jupyter) calonia 1 198 Jun-26-2019, 05:16 PM
Last Post: ThomasL
  Can someone please help me convert this simple C ROT cipher code to Python code? boohoo9 5 248 Jun-14-2019, 03:02 PM
Last Post: DeaD_EyE
  Help with finding correct topic in Python learning yahya01 1 283 Jun-06-2019, 05:01 PM
Last Post: buran
  my function is stuck on loop - even when it not supposed to be korenron 2 279 May-26-2019, 12:31 PM
Last Post: korenron
  learning to while loop iofhua 7 256 May-24-2019, 09:46 AM
Last Post: DarkCraftPlayz
  If Python 2.x source code and applies a transform it into valid Python 3.x code. vivekm 1 185 May-20-2019, 05:12 PM
Last Post: Larz60+
  Just completed Learning Python the Hard Way rxndy 5 378 Apr-27-2019, 01:48 AM
Last Post: rxndy
  while with try and except gets stuck in an endless loop? pcarra 3 245 Mar-27-2019, 07:50 PM
Last Post: pcarra

Forum Jump:

Users browsing this thread: 1 Guest(s)