Question: The user needs a program to interact with employee records. The kinds of interactions are Add an Employee (Create record), Show All Employees (Read records),
The user needs a program to interact with employee records. The kinds of interactions are "Add an Employee" (Create record), "Show All Employees" (Read records), "View an Employee" (Read one record), "Update an Employee" (Update or change a record), and "Delete an Employee" (Delete a record). These interactions form the standard data processes in much of business software Create, Read, Update, and Delete, which are known by the acronym CRUD.
The user needs to continue working with records until they are ready to tell the program. To do this, the program will present a menu of CRUD options and an option to Quit. The user will choose an option and the program will react accordingly.
For this lab, the program will only print out which option the user chose. In later labs, we will add more functionality.
Questions:
- What are the inputs needed to solve this programming problem (names and data types)?
- What are the desired outputs (data types and descriptions)?
- Since this is a menu of options, what do we do if the user enters something not on our list?
- What are the formats for the outputs?
The Python Program
- Create an new Python file called employee_program.py. Open the file in your Python editor environment. Copy your Python program template into this new file.
- In the file, change the program title to "EMPLOYEE PROGRAM". Save and run the file to make sure that it displays the title and the Program Complete message. It is always a good idea to run your incomplete program whenever it gets to a runnable state so you can fix errors as early as possible.
- Print the menu title and the menu options. Note that there is a tab escape sequence at the beginning of each of the menu lines.
- "\t-- Main Menu --"
- "\t1) Add an Employee"
- "\t2) Show All Employees"
- "\t3) View an Employee"
- "\t4) Update an Employee"
- "\t5) Delete an Employee"
- "\tQ) Quit"
- Get the choice from the user and save the string to a variable called user_choice
- Build the decision structure where each if or elif checks if the user_choice is equal to the strings 1, 2, 3, 4, 5, Q, or q. For each match, print a message stating that the user chose to -- and the name of the task. This is the part that will be changed drastically in future programs.
- Add an else clause to the decision structure to handle the user entering something that was not on the list. For the body of the else, print a message stating that the choice was not recognized and ask that the user try again.
- Add an input statement asking the user to "Press the Enter key to continue... ". There is no need to store this input() to a variable because we are only interested in whether the user pressed Enter.
- Print that the program is complete
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
