GeezerVison is showing github.com — Added common starting code for tutorials · kumar-samang/code_snippets@dc29fb6
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +19Lines changed: 19 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | + | | 2 | +def add(x, y): | | 3 | + """Add Function""" | | 4 | + return x + y | | 5 | + | | 6 | + | | 7 | +def subtract(x, y): | | 8 | + """Subtract Function""" | | 9 | + return x - y | | 10 | + | | 11 | + | | 12 | +def multiply(x, y): | | 13 | + """Multiply Function""" | | 14 | + return x * y | | 15 | + | | 16 | + | | 17 | +def divide(x, y): | | 18 | + """Divide Function""" | | 19 | + return x / y |
Collapse file Copy file name to clipboard +46Lines changed: 46 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | + | | 2 | +class Employee: | | 3 | + """A sample Employee class""" | | 4 | + | | 5 | + num_of_emps = 0 | | 6 | + raise_amt = 1.04 | | 7 | + | | 8 | + def __init__(self, first, last, pay): | | 9 | + self.first = first | | 10 | + self.last = last | | 11 | + self.pay = pay | | 12 | + | | 13 | + Employee.num_of_emps += 1 | | 14 | + | | 15 | + @property | | 16 | + def email(self): | | 17 | + return '{}.{}@email.com'.format(self.first, self.last) | | 18 | + | | 19 | + @property | | 20 | + def fullname(self): | | 21 | + return '{} {}'.format(self.first, self.last) | | 22 | + | | 23 | + def apply_raise(self): | | 24 | + self.pay = int(self.pay * self.raise_amt) | | 25 | + | | 26 | + def __repr__(self): | | 27 | + return "Employee('{}', '{}', {})".format(self.first, self.last, self.pay) | | 28 | + | | 29 | + | | 30 | +class Manager(Employee): | | 31 | + """A sample Manager class""" | | 32 | + | | 33 | + def __init__(self, first, last, pay, employees=None): | | 34 | + super().__init__(first, last, pay) | | 35 | + self.employees = employees if employees else [] | | 36 | + | | 37 | + def add_emp(self, emp): | | 38 | + if emp not in self.employees: | | 39 | + self.employees.append(emp) | | 40 | + | | 41 | + def remove_emp(self, emp): | | 42 | + if emp in self.employees: | | 43 | + self.employees.remove(emp) | | 44 | + | | 45 | + def __repr__(self): | | 46 | + return "Manager('{}', '{}', {}, {})".format(self.first, self.last, self.pay, self.employees) |
|