Assignment 3_CPT 200

docx

School

Ashford University *

*We aren’t endorsed by this school

Course

CPT 200

Subject

Computer Science

Date

Jan 9, 2024

Type

docx

Pages

16

Uploaded by 89gitar

Report
Running head: Functionality 3 1 Functionality 3 University of Arizona Global Campus
FUNCTIONALITY 3 2 Abstract This paper aims to discuss Assignment 3 in the CPT 200 course. Students were assigned to build upon the employee management Python application that displays an employee's information if the SSN belongs to the employee. The paragraphs below will explain a thought process, resources I utilized to write the code, and other pertinent information.
FUNCTIONALITY 3 3 Functionality 3 After reading the assignment instructions, I outlined how my program would run on paper. I planned on utilizing the "def" function to create separate functions in my code that will run when called on. According to this week's reading, a programmer can create a function using the keyword "def." The def keyword, a block of statements, and the new function's name, which can be any identifier, make up a function definition. A block is a set of statements that come after the function definition and are indented. When a function returns, the program resumes at the location of the first call, moving on to the statement that follows the call. (Miller, Vahid, & Lysecky, 2015) The plan was to utilize a menu system to include a "main" function continuously running. Firstly, I imported any Python add-ons I required before writing my code. In this case, I imported the time function to have a slight delay when a user viewed the employee's unique ID, which I will explain later. According to (Geeks for Geeks, 2022), the function will let you delay the execution of a command for however many seconds the programmer specifies. Afterward, I planned to create a unique function for each program task. I decided to include four functions. The first function I created was the primary menu function. The main function would be the first function and the infinite loop function. The purpose of the main function was to allow the program user to add an employee, view all employees, employee personal information lookup (by unique ID), and employee ID lookup. If the user did not know an employee's unique
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
FUNCTIONALITY 3 4 ID to access their personal information, the program provided that ID. In this care, the employee was assigned an ID number based on the item's index in a list. For example, the first entry in the database, that employer would have an ID of "0", the second an ID of "1," and so on. The first function also displays how many employees are currently in the program. I used the "len" function to determine how many employees were on the list and then printed it for display to keep track of employees entered in the system. According to our book, the "len" function counts how many items are in the list. (Python lists, n.d.) To choose a function in the application, the user had to input a number corresponding to a task. For example, entering the number 1 would allow the user to add an employee to the program, entering the number 2 would allow the user to view all employees, and so on. Based on the input, the user would then be transferred to the following applicable function based on their input. After they are done, the user can access the main menu's infinite loop. The only option that did not need functionality was the "view all employees" function. Instead, I print the list and return to the main loop. If the user chose option three, "Employee personal information lookup", they would be taken to a function that allowed them to input the employee's ID number. If they did not know the number, they could always look it up beforehand via option 4, which I will explain later. If the user did know the ID, then input the ID and then hit enter, they would be displayed with the employee's information in the specified format according to Assignment 3's instructions. The function then printed the employee's information by printing the list item (which stored the employees' information) by referencing the index of the list item. Then, the function utilized the
FUNCTIONALITY 3 5 sleep command to pause the execution for 2 seconds, allowing the user to view it without proceeding back to the main. After much trial and error, I got the function to work. The W3 school site aided me in my code writing. Finally, the last function allowed the user to look up the user ID (the corresponding index number of the list item) if they did not know it. I created a variable called "index1," which took the user input and checked the list to see if the index number (also the employee-assigned ID) existed and, if so, would display the ID or index of the list item. This allowed the user to identify which ID belonged to the employee. In conclusion, breaking out the program into functions made it easier for me to plan the program and how it would operate—creating an outline helped since I could plan the flow of my program and how each function would do a specific command based on what the user wanted.
FUNCTIONALITY 3 6 Screenshots
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
FUNCTIONALITY 3 7
FUNCTIONALITY 3 8
FUNCTIONALITY 3 9
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
FUNCTIONALITY 3 10
FUNCTIONALITY 3 11
FUNCTIONALITY 3 12
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
FUNCTIONALITY 3 13 References GeeksforGeeks. (2022, August 18). Time.sleep in Python . https://www.geeksforgeeks.org/sleep- in-python/ Miller, B., Vahid, F., & Lysecky, R. (2015). Programming in Python 3 . zyBooks. Python lists . (n.d.). https://www.w3schools.com/python/python_lists.asp Refsnes Data. (n.d.). Python if ... else . Python Conditions https://www.w3schools.com/python/python_conditions.asp
FUNCTIONALITY 3 14 Source Code # Imports time functionality import time # List for employeee names. names = [] # List for employees information. data = [] # Functions. # Main menu function def main (): print ( "-----------------------------------------" ) print ( "Welcome to the Employee Management System! \n " ) print ( "Number of employees in the system: " , len ( names ), " \n " ) choice_1 = input ( "1) Add an employee. \n 2) View all employees. \n 3) Employee personal information lookup. \n 4. Employee ID lookup. \n\n > > >" ) if choice_1 == "1" : add_employee () elif choice_1 == "2" : print ( " \n\n " ) print ( names ) main () elif choice_1 == "3" : lookup () elif choice_1 == "4" : id_lookup () else : print ( "Input error. please try again." ) main () # Function to add employee to list. def add_employee (): while True : counter = 0
FUNCTIONALITY 3 15 print ( "------------------------------------" ) name = input ( "Please input employees name: " ) ssn = input ( "Please enter the employees Social Security Number (###-###-####): " ) fone = input ( "Please enter the employees phone number (###-###-####): " ) email = input ( "Please enter the employees email address: " ) salary = input ( "Please enter the employees salary: " ) combo = name + ',' + ssn + ',' + fone + ',' + email + ',' + salary names . append ( name ) data . append ( combo ) counter = counter + 1 choice = input ( "Would you like to enter another employee? (y / n): \n\n > > >" ) if choice == "y" : add_employee () elif choice == "n" : main () else : print ( "Input error, please try again." ) add_employee () # Displays all employees information based on their system assigned ID (its the tuple) def lookup (): while True : i = 0 for i in data : print ( "------------------------------------" ) user_answer = int ( input ( "To view an employees information type their ID number: " )) names data print ( data [ user_answer ]) main () # Provide the user with the employess ID (aka the tuple to get the information) def id_lookup (): employeeid = input ( "Please input the employees name to display the employees ID number: \n\n > > >" )
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
FUNCTIONALITY 3 16 if employeeid in names : index1 = names . index ( employeeid ) print ( index1 ) time . sleep ( 2 ) main () else : print ( "Input error, please try again." ) id_lookup () # Executes main menu function main ()