Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The person assisting added things to my code but did not explain what they were for or why they are needed. An whats worse is
The person assisting added things to my code but did not explain what they were for or why they are needed. An whats worse is they are incomplete as well. Leaving me confused..
Why was if name main: added? Why is it necessary? I tried to add a main earlier and it produced nothing at all. But this just gives me an error saying "NameError: name 'name' is not defined".
Im not opposed to an addition but if I dont know what its for or whyit was added an it was added incorrectly it how would this help?
import pickle
class Employee:
def initself Fname Lname social rate hrsworked:
self.Fname Fname.upper
self.Lname Lname.upper
self.social social
self.rate rate
self.hrsworked hrsworked
# Getters & setters
def getFnameself:
return self.Fname
def setFnameself Fname:
self.Fname Fname.upper
def getLnameself:
return self.Lname
def setLnameself Lname:
self.Lname Lname.upper
def getsocialself:
return self.social
def setsocialself social:
self.social social
def getrateself:
return self.rate
def setrateself rate:
self.rate rate
def gethrsworkedself:
return self.hrsworked
def sethrsworkedself hrsworked:
self.hrsworked hrsworked
def getgrossself:
if self.hrsworked :
return self.rateselfhrsworked selfrate
else:
return self.hrsworked self.rate
def strself:
lastfourdigits self.social:
gross self.getgross
return fselfFnamelastfourdigitsgross:f
def EmployeeInfo:
try:
with openC:employeedat", wb as outfile:
while True:
Fname inputEnter an employee first name:
Lname inputEnter the last name the employee:
social inputEnter the social security number it must be digits:
while lensocial:
printThe social security number must be digits in length."
printPlease enter again."
social inputEnter the social security number it must be digits:
rate floatinputEnter the pay rate of the employee:
hrsworked floatinputEnter the hours worked by the employee:
employee EmployeeFname Lname, social, rate, hrsworked
pickle.dumpemployee outfile
another inputEnter another employee? yn:
if another.lowern:
break
except IOError:
printError opening or writing to employee.dat"
except pickle.PickleError:
printError using pickle module"
def ShowData:
try:
with openC:employeedat", rb as file:
print:::::formatEmployee Name", ID "Hours Worked", "Pay Rate", "Gross Pay"
while True:
try:
obj pickle.loadfile
print:::::formatobjgetFname obj.getLname obj.getsocial: obj.gethrsworked obj.getrate obj.getgross
except EOFError:
break
except FileNotFoundError:
printThe file could not be found."
if name main:
EmployeeInfo
ShowData
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started