Created
November 22, 2021 03:52
-
-
Save Otumian-empire/269961bf2e3309a630362a7c7e53259b to your computer and use it in GitHub Desktop.
More example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# file name: employee.py | |
# calculating the gross pay | |
class Employee: | |
def __init__(self, name, job, salary): | |
self.name = name | |
self.job = job | |
self.salary = salary | |
# some constants | |
self.WORKING_DAYS_IN_A_MONTH = 30 | |
self.WORKING_HOURS_IN_A_DAY = 12 | |
self.PAY_RATE = 0.25 | |
# the total number of hours the employee should | |
# have done in a whole month | |
self.WORKED_HOURS = self.WORKING_HOURS_IN_A_DAY * self.WORKING_DAYS_IN_A_MONTH | |
# calculate the gross pay based on the time employee | |
# did for the whole month | |
# the hours here is the total hours that the employee | |
# has overworked | |
def return_gross_pay(self, hours): | |
gross_pay = 0 | |
if hours > self.WORKED_HOURS: | |
over_time = hours - self.WORKED_HOURS | |
over_time_pay = over_time + (self.salary * self.PAY_RATE) | |
gross_pay = self.salary + over_time_pay | |
else: | |
gross_pay = self.salary | |
return gross_pay |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment