here is my program: i am using python 3.4.3.. i would like you to run my program
ID: 3591227 • Letter: H
Question
here is my program: i am using python 3.4.3.. i would like you to run my program read the assignments and fix the mistakes. Thanks! I always rate my answer. the program is working but i still have to fixed duplicate SSN.. the same ssn cannot be duplicate as the assignments say.. Also when i delete an entry it still print both "ssn not found" and" successful deleted"
empRoster = {}
#funtion to display Menu
def createMenu():
print ("1. Add new Employee")
print ("2. Print Report(All Employees)")
print ("3. Print Info for Individual Employees")
print ("4. Calculate Average Salary of all Employees")
print ("5. Delete a Employee")
print ("6. Quit")
#Function to validate choice
def getValidChoice():
inp = 0
while(True):
createMenu()
inp = int(input("Enter Your choice:"))
if inp>0 and inp <7:
break
else:
print ("Invalid Input")
continue
return inp
def isValidSSN(tmpSSN):
if len (tmpSSN) ==11 and tmpSSN[3]=='-' and tmpSSN[6]=='-' : #Checking ssn pattern
return True
else:
return False
#Function to all employee in Dictionary
def addEmployee(list):
ssn = input("Enter SSN:")
while True:
if (isValidSSN(ssn)): # validating SSN
#break
#else:
name = input("Enter Name:")
salary = input("Enter Salary:")
empRoster[ssn]=[name,salary] # adding in Dictionary
break
else:
return False
#Function to print report of all employees
def printEmployeeList(list):
print ("SSN Name Salary")
print ("---------------------------------------------------")
for ssn in empRoster.keys():
l = empRoster[ssn]
print (ssn+" "+l[0]+" "+l[1]) # printing all info
#Function to print info or one employee
def printEmployee(list):
name = input("Enter Name:")
for ssn in empRoster.keys():
l = empRoster[ssn]
if l[0] == name:
print ("Name: "+l[0]) #printing name
print ("SSN: "+ssn) #printing ssn
print ("Salary: "+l[1])#printing salary
return
#else:
print ("The employee is not in the roster.")
#Function to calculate average of all employees salary
def calculate():
total =0
count = 0
for ssn in empRoster.keys():
l = empRoster[ssn]
total = total + int(l[1]) #adding salary
count = count + 1 #counting employees
print ("Average of All Employees Salary :"+str(total/count)) #printing average
#Function to delete Employee
def deleteEmployee(list):
s = input("Enter SSN:")
#found = 0
for ssn in empRoster.keys():
if ssn == s:
empRoster.pop(ssn)
print ("Successfully Deleted")
#found = 1
break;
#if found:
#empRoster.pop(ssn)
#print ("Successfully Deleted")
else:
print ("SSN is not found")
def main():
list = []
quit = False
while quit != True:
choice = getValidChoice()
if choice == 1:
addEmployee(list)
if choice == 2:
printEmployeeList(empRoster)
if choice == 3:
printEmployee(empRoster)
if choice == 4:
calculate()
if(choice == 5):
deleteEmployee(empRoster)
if choice == 6:
quit = True
break
main()
#
----------
CSIS 153 Fall 2017 Program 5 20 pts Write a program that uses Python's Dictionaries to accomplish the following. Be sure to MODULARIZE your program, and pass everything that a function needs in as parameters. Create an empty dictionary called empRoster. Use these functions that were created previously: createMenu getValidChoice Create this function: isValidSSNtmpSSN) which accepts any string and returns True if the string is in the format: ######### Otherwise, it returns False. Continuously print the menu shown below until the user chooses the option to quit. Be sure to use the getValidChoice function to ensure the choice is numeric and within the range allowed. 1) Add Employee 2) Print Report (All Employees) 3) Print Info for Individual Employee 4) Calculate Average salary of all employees 5) Delete Employee 6) Quit Create functions for each of the menu options - be sure to pass in the dictionary as a parameter! Add Employee option: (write a function to handle this - make sure to pass enough parameters into this!) Use Python input statements to have the user enter the following information: ssn, name, salary Make sure to call the isValidSSN function to ensure they enter a valid social security number Check to ensure that the SSN isn'ta duplicate! If it is, keep asking the user to enter a different SSN until a unique one is entered. NO DUPLICATES ALLOWED! Store the information in the empRoster dictionary which maps SSNs to a list containing name, salary Example of how the empRoster will look after 2 calls to the "addEmp" function: { "111-11-1111": [“Jill Jones", 40000 ), "222-22-2222": ["Sam Smith",30000), "333-33-3333":["Cathy", "Crawley", 50000] Print Report option: (write a function to handle this make sure to pass enough parameters into this) Print the Column Headings Print the information for each employee on a separate line. NOTE: use Python's format method to ensure that the information is aligned in columns.Explanation / Answer
I have pasted the code on codeshare as chegg does not follow indenting while showing the answers, which is vital for python programs.
Open this link in browser - https://codeshare.io/aYbZgR - Comment if need anything else in code.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.