Skip to content

Instantly share code, notes, and snippets.

@huytung228
Created July 20, 2021 04:14
Show Gist options
  • Save huytung228/5d862d4b7b420243d834a4845071a991 to your computer and use it in GitHub Desktop.
Save huytung228/5d862d4b7b420243d834a4845071a991 to your computer and use it in GitHub Desktop.
class Employee:
raise_amount = 1.05
num_of_emps = 0
def __init__(self, first, last, pay):
self.first = first
self.last = last
self.pay = pay
self.email = first+'.'+last+'@company.com'
Employee.num_of_emps += 1
def fullname(self):
return f"{self.first} {self.last}"
def apply_raise(self):
# access class variables can perform by self or Employee
# self.pay = int(self.pay * self.raise_amount)
self.pay = int(self.pay * Employee.raise_amount)
@classmethod
def set_raise_amt(cls, amount):
cls.raise_amount = amount
@classmethod
def from_string(cls, emp_str):
firsr, last, pay = emp_str.split('-')
return cls(firsr, last, pay)
@staticmethod
def is_workday(day):
if day.weekday() == 5 or day.weekday() == 6:
return False
return True
emp_str1 = 'Le-HuyTung-70000'
e1 = Employee.from_string(emp_str1)
print(e1.email)
import datetime
my_date = datetime.datetime(2016, 7, 10)
print(Employee.is_workday(my_date))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment