PYTHON Add a method calculate_pay() to the Employee class. The method should ret
ID: 3770170 • Letter: P
Question
PYTHON
Add a method calculate_pay() to the Employee class. The method should return the amount to pay the employee by multiplying the employee's wage and number of hours worked.
Edit the following code:
class Employee:
def __init__(self):
self.wage = 0
self.hours_worked = 0
# def ... Add new method here ...
# ...
alice = Employee()
alice.wage = 9.25
alice.hours_worked = 35
print('Alice: Net pay: %f' % alice.calculate_pay())
bob = Employee()
bob.wage = 11.50
bob.hours_worked = 20
print('Bob: Net pay: %f' % bob.calculate_pay())
Explanation / Answer
Here is the code for you. If you have any further queries, just get back to me.
#!/usr/bin/python
class Employee:
def __init__(self):
self.wage = 0
self.hours_worked = 0
def calculate_pay(self):
return self.wage * self.hours_worked;
alice = Employee()
alice.wage = 9.25
alice.hours_worked = 35
print('Alice: Net pay: %f' % alice.calculate_pay())
bob = Employee()
bob.wage = 11.50
bob.hours_worked = 20
print('Bob: Net pay: %f' % bob.calculate_pay())
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.