forked from CoreyMSchafer/code_snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added common starting code for tutorials
- Loading branch information
Corey Schafer
authored and
Corey Schafer
committed
Mar 25, 2017
1 parent
34653e5
commit dc29fb6
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
def add(x, y): | ||
"""Add Function""" | ||
return x + y | ||
|
||
|
||
def subtract(x, y): | ||
"""Subtract Function""" | ||
return x - y | ||
|
||
|
||
def multiply(x, y): | ||
"""Multiply Function""" | ||
return x * y | ||
|
||
|
||
def divide(x, y): | ||
"""Divide Function""" | ||
return x / y |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
class Employee: | ||
"""A sample Employee class""" | ||
|
||
num_of_emps = 0 | ||
raise_amt = 1.04 | ||
|
||
def __init__(self, first, last, pay): | ||
self.first = first | ||
self.last = last | ||
self.pay = pay | ||
|
||
Employee.num_of_emps += 1 | ||
|
||
@property | ||
def email(self): | ||
return '{}.{}@email.com'.format(self.first, self.last) | ||
|
||
@property | ||
def fullname(self): | ||
return '{} {}'.format(self.first, self.last) | ||
|
||
def apply_raise(self): | ||
self.pay = int(self.pay * self.raise_amt) | ||
|
||
def __repr__(self): | ||
return "Employee('{}', '{}', {})".format(self.first, self.last, self.pay) | ||
|
||
|
||
class Manager(Employee): | ||
"""A sample Manager class""" | ||
|
||
def __init__(self, first, last, pay, employees=None): | ||
super().__init__(first, last, pay) | ||
self.employees = employees if employees else [] | ||
|
||
def add_emp(self, emp): | ||
if emp not in self.employees: | ||
self.employees.append(emp) | ||
|
||
def remove_emp(self, emp): | ||
if emp in self.employees: | ||
self.employees.remove(emp) | ||
|
||
def __repr__(self): | ||
return "Manager('{}', '{}', {}, {})".format(self.first, self.last, self.pay, self.employees) |