-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial_2_class_variables.py
More file actions
43 lines (34 loc) · 1.06 KB
/
tutorial_2_class_variables.py
File metadata and controls
43 lines (34 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
Python OODP Tutorial 2: Class Variables
"""
class Employee:
raise_amount = 1.04
num_of_emps = 0
def __init__(self, first, last, pay): # constructor
self.first = first
self.last = last
self.email = "{}.{}@company.com".format(first, last)
self.pay = pay
Employee.num_of_emps += 1
def fullname(self): # method; remember to put self
return "{} {}".format(self.first, self.last)
def apply_raise(self):
self.pay = int(self.pay * self.raise_amount) # Employee.raise_amount works too; pending on the situation, choose appropriately
emp_1 = Employee("Test", "User", 1500)
print(emp_1.pay)
emp_1.apply_raise()
print(emp_1.pay)
# emp_1 = Employee("Test", "User", 1500)
# emp_2 = Employee("Test2", "User2", 1600)
# Employee.raise_amount = 1.05
# emp_1.apply_raise()
# emp_2.apply_raise()
# print(emp_1.pay)
# print(emp_2.pay)
emp_1 = Employee("Test", "User", 1000)
emp_2 = Employee("Test2", "User2", 2000)
emp_1.raise_amount = 1.05
emp_1.apply_raise()
emp_2.apply_raise()
print(emp_1.pay)
print(emp_2.pay)