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 [Link] on 03-20-2022 [Link] GMT -05:00
[Link]
Completed Functionality:
This study source was downloaded by 100000784703851 from [Link] on 03-20-2022 [Link] GMT -05:00
[Link]
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 [Link] on 03-20-2022 [Link] GMT -05:00
[Link]
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: ')
[Link](input())
print('Enter the employee SSN: ')
[Link](input())
print('Enter the employee Phone Number: ')
[Link](input())
print('Enter the employee Email: ')
[Link](input())
print('Enter the employee Salary: $ ')
[Link](input())
[Link](Employee)
def view_all_Employees():
This study source was downloaded by 100000784703851 from [Link] on 03-20-2022 [Link] GMT -05:00
[Link]
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 [Link] on 03-20-2022 [Link] GMT -05:00
[Link]
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 [Link] on 03-20-2022 [Link] GMT -05:00
[Link]
Reference:
Net-informations, (n.d.). Python control structures. Retrieved from [Link]
[Link]/python/flow/[Link]
This study source was downloaded by 100000784703851 from [Link] on 03-20-2022 [Link] GMT -05:00
[Link]
Powered by TCPDF ([Link])