Answered step by step
Verified Expert Solution
Link Copied!

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 init(self, Fname='', Lname='', social='', rate=0, hrs_worked=0):
self.Fname = Fname.upper()
self.Lname = Lname.upper()
self.social = social
self.rate = rate
self.hrs_worked = hrs_worked
# Getters & setters
def get_Fname(self):
return self.Fname
def set_Fname(self, Fname):
self.Fname = Fname.upper()
def get_Lname(self):
return self.Lname
def set_Lname(self, Lname):
self.Lname = Lname.upper()
def get_social(self):
return self.social
def set_social(self, social):
self.social = social
def get_rate(self):
return self.rate
def set_rate(self, rate):
self.rate = rate
def get_hrs_worked(self):
return self.hrs_worked
def set_hrs_worked(self, hrs_worked):
self.hrs_worked = hrs_worked
def get_gross(self):
if self.hrs_worked >40:
return (40* self.rate)+((self.hrs_worked -40)(self.rate *1.5))
else:
return self.hrs_worked * self.rate
def str(self):
last_four_digits = self.social[-4:]
gross = self.get_gross()
return f"{self.Fname}{last_four_digits}{gross:.2f}"
def EmployeeInfo():
try:
with open("C:\\employee.dat", "wb") as outfile:
while True:
Fname = input("Enter an employee first name: ")
Lname = input("Enter the last name the employee: ")
social = input("Enter the social security number (it must be 9 digits): ")
while len(social)!=9:
print("The social security number must be 9 digits in length.")
print("Please enter again.")
social = input("Enter the social security number (it must be 9 digits): ")
rate = float(input("Enter the pay rate of the employee: "))
hrs_worked = float(input("Enter the hours worked by the employee: "))
employee = Employee(Fname, Lname, social, rate, hrs_worked)
pickle.dump(employee, outfile)
another = input("Enter another employee? (y/n): ")
if another.lower()=="n":
break
except IOError:
print("Error opening or writing to employee.dat")
except pickle.PickleError:
print("Error using pickle module")
def ShowData():
try:
with open("C:\\employee.dat", "rb") as file:
print("{:<20}{:<15}{:<10}{:<10}{:<10}".format("Employee Name", "ID", "Hours Worked", "Pay Rate", "Gross Pay"))
while True:
try:
obj = pickle.load(file)
print("{:<20}{:<15}{:<10}{:<10}{:<10}".format(obj.get_Fname()+""+ obj.get_Lname(), obj.get_social()[-4:], obj.get_hrs_worked(), obj.get_rate(), obj.get_gross()))
except EOFError:
break
except FileNotFoundError:
print("The file could not be found.")
if name =="__main__":
EmployeeInfo()
ShowData()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

IBM Db2 11 1 Certification Guide Explore Techniques To Master Database Programming And Administration Tasks In IBM Db2

Authors: Mohankumar Saraswatipura ,Robert Collins

1st Edition

1788626915, 978-1788626910

More Books

Students also viewed these Databases questions