Advertisement
DerioFT

user.py patch 2

Jan 19th, 2021
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. class User:
  2.  
  3.     def __init__(self, first, last, attempts=0):
  4.         self.first_name = first
  5.         self.last_name = last
  6.         self.login_attempts = attempts
  7.  
  8.     def describe_user(self):
  9.         print(f'Nama depan : {self.first_name}\nNama belakang : {self.last_name}')
  10.  
  11.     def greet_user(self):
  12.         print(f'Hi, welcome {self.first_name} {self.last_name}')
  13.  
  14.     def increment_login_attempts(self):
  15.         self.login_attempts += 1
  16.  
  17.     def reset_login_attempts(self, number):
  18.         self.login_attempts = number
  19.  
  20. user1 = User('Budi', 'Setiawan')
  21. user1.describe_user()
  22. user1.greet_user()
  23. for a in range (3):
  24.     user1.increment_login_attempts()
  25.  
  26. user1.login_attempts = 0
  27.  
  28. class Admin(User):
  29.  
  30.     def __init__(self, first, last, attempts=0):
  31.         super().__init__(first, last, attempts)
  32.         #self.privileges = ['can add post', 'can delete post', 'can ban user', '', '']
  33.         self.privileges = Privileges()
  34.  
  35.     '''
  36.     def show_privileges(self):
  37.         print('privileges : ')
  38.         counter = 1
  39.         for privileges in self.privileges:
  40.             print(counter, privileges.title())
  41.             counter = counter + 1
  42.     '''
  43. class Privileges:
  44.  
  45.     def __init__(self):
  46.         self.privileges = ['can add post', 'can delete post', 'can ban user', 'can view any posts', 'can add new user']
  47.  
  48.     def show_privileges(self):
  49.         print('privileges : ')
  50.         counter = 1
  51.         for privileges in self.privileges:
  52.             print(counter, privileges.title())
  53.             counter = counter + 1
  54.  
  55. userAdmin = Admin('A', 'B')
  56. userAdmin.privileges.show_privileges()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement