-
Notifications
You must be signed in to change notification settings - Fork 19
/
admin.py
82 lines (70 loc) · 2.36 KB
/
admin.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Author: Bojan G. Kalicanin
# Date: 03-Oct-2016
# Modelling real-world users and administrators of the website
class User():
"""Trying to model real-world users of the some website."""
def __init__(
self,
first_name,
last_name,
username,
age,
location):
"""Initializing attributes of the class Users."""
self.first_name = first_name
self.last_name = last_name
self.username = username
self.age = age
self.location = location
self.login_attempts = 0
def describe_user(self):
"""Method that prints summary of the user information."""
print("We have stored next information about user " +
self.first_name.title() + " " + self.last_name.title() +
":")
print("- Username: " + self.username)
print("- Age: " + str(self.age))
print("- Location: " + self.location.title())
def greet_user(self):
"""Method that print personalized greeting to the user."""
print("Hello " + self.first_name.title() + " " +
self.last_name.title() + ", welcome back!")
def increment_login_attempts(self):
"""Increment login attempts for 1."""
self.login_attempts += 1
def reste_login_attempts(self):
"""Method that resets value of login attempts to 0."""
self.login_attempts = 0
class Admin(User):
"""Trying to model real-world administrators of some website."""
def __init__(
self,
first_name,
last_name,
username,
age,
location
):
"""
Initializing attributes of the parent class User.
Adding attributes specific to the Class Admin.
"""
super().__init__(
first_name,
last_name,
username,
age,
location
)
self.privileges = [
'can add post',
'can delete post',
'can ban user',
]
def show_privileges(self):
"""Methods that shows privileges of the user."""
print("The user " + self.username + " has next privileges:")
for privilege in self.privileges:
print("- " + privilege)
my_user = Admin('John', 'Doe', 'jdoe', 30, 'new york')
my_user.show_privileges()