0% found this document useful (0 votes)
191 views

Week 4 Assignment: Functionality 4

The document describes an assignment to improve an employee management system by adding two new functions: search employee by social security number and edit employee information. Loops and control statements are used to improve the view all employees functionality. Functions are defined to add a new employee, view all employees, search for an employee, and edit an employee's information. The code provided implements these new functions and allows the user to interact with a menu to perform actions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
191 views

Week 4 Assignment: Functionality 4

The document describes an assignment to improve an employee management system by adding two new functions: search employee by social security number and edit employee information. Loops and control statements are used to improve the view all employees functionality. Functions are defined to add a new employee, view all employees, search for an employee, and edit an employee's information. The code provided implements these new functions and allows the user to interact with a menu to perform actions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Week 4 Assignment: Functionality 4

Christopher White
CPT200: Fundamentals of Programming Languages
Prof. Amjad Alkilani
16 August 2021

This study source was downloaded by 100000784703851 from CourseHero.com on 03-20-2022 20:15:51 GMT -05:00

https://www.coursehero.com/file/103443834/Programmin-Week-4-Assignmentdocx/
Completed Functionality:

This study source was downloaded by 100000784703851 from CourseHero.com on 03-20-2022 20:15:51 GMT -05:00

https://www.coursehero.com/file/103443834/Programmin-Week-4-Assignmentdocx/
OUTPUT:

Explanation:

This Week’s Employee Management System Functionality 4, I continued to use variables,


functions, and control structures to improve the “View all Employees” functionally that I also
develop in Week 3. In this activity, I utilize functions and the passing of parameters to add two
new functionalities to my Employee Management System. These two new functions are Search
employee by SSN and Edit employee information.

This study source was downloaded by 100000784703851 from CourseHero.com on 03-20-2022 20:15:51 GMT -05:00

https://www.coursehero.com/file/103443834/Programmin-Week-4-Assignmentdocx/
A control structure (or flow of control) is a block of programming that analyses variables and
chooses a direction in which to go based on given parameters (net-information, n.d.). The Loops
and Control Statements (continue, break and pass) in Python helps in improving the View all
Employees functionality that able to view the results for the new functions, Search employee by
SSN and Edit employee information. The while loop used in this assignment tells the computer
to do something as long as the condition is met and to exit from this while loop before the loop
has finished fully iterating over all the step values, a break statement was used. The break
statement allows to exit a loop from any point within its body.
The purpose of Search employee by SSN is to make use of looping and string parsing to search
all the employees in the list and returns the information of the employee who has an SSN like the
one that the user provided. And the purpose of function Edit employee information is to allow
the user to edit the information of the selected user.

Script for Functionality 4:


employees = []
count = 0
def add_employee():
global count
Employee = []
count += 1
print('Enter the name of employee: ')
Employee.append(input())
print('Enter the employee SSN: ')
Employee.append(input())
print('Enter the employee Phone Number: ')
Employee.append(input())
print('Enter the employee Email: ')
Employee.append(input())
print('Enter the employee Salary: $ ')
Employee.append(input())
employees.append(Employee)

def view_all_Employees():

This study source was downloaded by 100000784703851 from CourseHero.com on 03-20-2022 20:15:51 GMT -05:00

https://www.coursehero.com/file/103443834/Programmin-Week-4-Assignmentdocx/
for i in employees:
print("-----------------------"+i[0]+"-----------------------")
print('SSN: ',i[1])
print('Phone: ',i[2])
print('Email: ',i[3])
print('Salary: $',i[4])
print("-------------------------------------------------------")

def search_Employee(SSN):
findIdex=0
for i in employees:
if(i[1]==SSN):
return findIdex
findIdex+=1

return -1

while(True):
print('Enter -1 to exit')
print('Enter 1 to add employee')
print('Enter 2 to view all employees')
print('Enter 3 to search employee by SSN')
print('Enter 4 to edit employee information')
a=int(input())
if(a==-1):
break
elif(a==1):
add_employee()

This study source was downloaded by 100000784703851 from CourseHero.com on 03-20-2022 20:15:51 GMT -05:00

https://www.coursehero.com/file/103443834/Programmin-Week-4-Assignmentdocx/
print()
elif(a==2):
view_all_Employees()
print()
elif(a==3):
ssn=input('Enter the SSN to find the employee: ')
empIndex=search_Employee(ssn)
if(empIndex>=0):
print('-------------------',employees[empIndex][0],'----------------------------')
print('SSN: ',employees[empIndex][1])
print('Phone: ',employees[empIndex][2])
print('Email: ',employees[empIndex][3])
print('Salary: $ ',employees[empIndex][4])
print('------------------------------------------------------------------------')
else:
print('Employees with SSN '+SSN+' is not found.\n')
elif(a==4):
SSN=input('Enter the SSN to edit employee information:')
empIndex=search_Employee(SSN)
if(empIndex>=0):
employees[empIndex][0]=input('Enter update Name: ')
employees[empIndex][2]=input('Enter Phone number: ')
employees[empIndex][3]=input('Enter Email: ')
employees[empIndex][4]=input('Enter Salary: ')
print('Employees information has been updated.\n')
else:
print('Employee with SSN '+SSN+' is not found.\n')
else:
print('invalid output')

This study source was downloaded by 100000784703851 from CourseHero.com on 03-20-2022 20:15:51 GMT -05:00

https://www.coursehero.com/file/103443834/Programmin-Week-4-Assignmentdocx/
Reference:
Net-informations, (n.d.). Python control structures. Retrieved from http://net-
informations.com/python/flow/default.htm

This study source was downloaded by 100000784703851 from CourseHero.com on 03-20-2022 20:15:51 GMT -05:00

https://www.coursehero.com/file/103443834/Programmin-Week-4-Assignmentdocx/
Powered by TCPDF (www.tcpdf.org)

You might also like