Week 4 Assignment: Functionality 4
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 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.
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)