forked from eyahi/AP-Python-Assignment-MSc-NUN
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAss2q2.py
More file actions
55 lines (44 loc) · 1.57 KB
/
Ass2q2.py
File metadata and controls
55 lines (44 loc) · 1.57 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
44
45
46
47
48
49
50
51
52
53
54
55
#a)
class User():
def __init__(self, first_name, last_name, age, email):
self.first_name = first_name
self.last_name = last_name
self.age = age
self.email = email
self.login_attempts = 0
def describe_user(self):
print(f"User: {self.first_name} {self.last_name}")
print(f"Age: {self.age}")
print(f"Email: {self.email}")
def greet_user(self):
print(f"Hello, {self.first_name}!")
def increment_login_attempts(self):
self.login_attempts +=1
def reset_login_attempts(self):
self.login_attempts = 0
user1 = User('John', 'Doe', '25', 'john.doe@email.com')
user2 = User("Jane", "Smith", 30, "jane.smith@email.com")
user1.describe_user()
user1.greet_user()
user2.describe_user()
user2.greet_user()
#b)
user = User("Alice", "Johnson", 28, "alice.j@email.com")
user.increment_login_attempts()
user.increment_login_attempts()
print(f"Login attempts: {user.login_attempts}")
user.reset_login_attempts()
print(f"Login attempts after reset: {user.login_attempts}")
#c)
class Admin(User):
def init(self, first_name, last_name, age, email):
super().init(first_name, last_name, age, email)
self.privileges = []
def show_privileges(self):
print("Admin privileges:")
for privilege in self.privileges:
print(f"- {privilege}")
najib = Admin("Admin", "User", 35, "admin.user@email.com")
najib.describe_user()
najib.privileges = ['\ncan reset password','can add post','can review post']
najib.show_privileges()