forked from fenyx-it-academy/Class5-Python-Module-Week5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion_4.py
More file actions
24 lines (22 loc) · 847 Bytes
/
Question_4.py
File metadata and controls
24 lines (22 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'''## Question 4:
* Define the `Employee` class with an `__init__()` method
* Define a class variable `new_id` and set it equal to `1`
* Each Employee instance will need its own unique ID. Thus, inside `__init__()`, define `self.id` and set it equal to the class variable `new_id`
* Lastly, increment `new_id` by `1`
* Define a `say_id()` method
* Inside `say_id()`, output the string `"My id is "` and then the instance id.
* Define the variable e1 and set it to an instance of Employee
* Define the variable e2 and set it to an instance of Employee
* Have both e1 and e2 output their ids'''
class Employee:
new_id=1
def __init__(self, id):
self.id=id
self.id = Employee.new_id
Employee.new_id+=1
def say_id(self):
print(f"My id is: {self.id}")
e1 = Employee()
e2 = Employee()
e1.say_id()
e1.say_id()