from user import Admin austin = Admin('austin', 'breedveld', 'a_breedveld', '*****@*****.**', 'arizona') austin.describe_user() austin_privileges = [ 'can reset passwords', 'can moderate discussions', 'can suspend accounts', ] austin.privileges.privileges = austin_privileges print("\nThe admin " + austin.username + " has these privileges: ") austin.privileges.show_privileges()
class Privileges(): def __init__(self, privileges=[]): self.privileges = privileges def show_privileges(self): print("\nPrivileges:") if self.privileges: for privilege in self.privileges: print("- " + privilege) else: print("- This user has no privileges") eric = Admin('Eric', 'Ustra', 'e_sturdy', '*****@*****.**', 'alaska') eric.describe_user() eric.privileges.show_privileges() print("\nAdding privileges...") eric_privileges = [ 'can reset passwords', 'can moderate discussions', 'can suspend accounts', ] eric.privileges.privileges = eric_privileges eric.privileges.show_privileges() from user import Admin ##Issues
# coding=gbk # 9.2 导入类的练习 导入Admin类 """从用户模块中导入 user类 admin类 privilege类""" from user import User, Admin, Privileges user_1 = Admin('lei', 'tianfu', 'male', 21) user_1.privileges.show_privileges() user_1.describe_user()
from user import Admin andy = Admin('andy', 'nahayo', 'naandy', '*****@*****.**', 'Bujumbura') andy.describe_user() andy_privileges = [ 'can reset passwords', 'can moderate discussions', 'can suspend accounts', ] andy.privileges.privileges = andy_privileges print("\nThe admin " + andy.username + " has these privileges: ") andy.privileges.show_privileges()
from user import Admin my_user=Admin('Faiz','Khan') my_user.describe_user() my_user.privileges.show_privileges()
from user import User, Admin user = User('Alex', 'Priv', age='19', adress='Bryansk') user.describe_user() user.privileges.show_privileges() user.increment_login_attempts() user.increment_login_attempts() user.increment_login_attempts() print( f"Количество посещений {user.person_data['first_name']} - {user.login_attempts}" ) user.reset_login_attempts() print( f"Сброшено количество посещений {user.person_data['first_name']} - {user.login_attempts}" ) admin = Admin('Sanya', 'Boss', age='34', adress='Bryansk', status='admin') admin.describe_user() admin.privileges.show_privileges()
from user import Admin blee = Admin('brandon', 'lee', '*****@*****.**') blee.describe_user() blee.privileges.show_privileges()
from user import Admin john = Admin('john', 'biden', 'j_bid', '*****@*****.**', 'arizona') john.describe_user() john_privileges = [ 'can reset passwords', 'can suspend accounts', 'can moderate discussions', ] john.privileges.privileges = john_privileges print("\nThe admin " + john.username + " has these privileges: ") john.privileges.show_privileges()
print( '\n\tВводите сначала атрибут, а на следующей строке - значение.\n\n\t\t__!!! По завершении введите "конец" !!!___' ) active = True while active: key = input("\nатрибут: ") if key == 'конец': active = False continue value = input("значение: ") if value == 'конец': active = False continue другое[key] = value user1 = Admin(имя, фамилия, **другое) user1.describe_user() user1.greet_user() user1.priv.privileges = priveleges_message user1.priv.show_privileges() else: user1 = Admin(имя, фамилия) user1.describe_user() user1.greet_user() user1.priv.privileges = priveleges_message user1.priv.show_privileges()
from user import Admin admin_1 = Admin('xinhan', 'niu', 21, 'May 2nd') admin_1.describe_user()
from user import Admin fabiano = Admin('fabiano', 'ferreira', 'f_ferreira', '*****@*****.**', 'são paulo') fabiano.describe_user() fabiano_privileges = [ 'Can reset passwords', 'Can moderate discussions', 'Can suspend accounts', ] fabiano.privileges.privileges = fabiano_privileges print("\nThe admin " + fabiano.username + " has these privileges: ") fabiano.privileges.show_privileges()
from user import User, Privileges, Admin superuser = Admin('Daniel', 'Oh', 25, 'male', 'texas') superuser.describe_user() superuser.privileges.show_privileges()
from user import Admin # 实例 liming = Admin("li", "ming", "male") liming.privileges.add_privileges( ["can add post", "can delete post", "can ban user"]) liming.describe_user() liming.privileges.show_privileges()
from user import Admin jeff = Admin('jeff', 'winger', 'wingman', '*****@*****.**', 'colorado') jeff.describe_user() jeff_privileges = ['teach', 'drink', 'give inspiring speeches'] jeff.privileges.privileges = jeff_privileges jeff.privileges.show_privileges()
from user import Admin takanory = Admin('takanori', 'suzuki', 'takanory', '*****@*****.**', 'toshima-ku') takanory.describe_user() takanory_privileges = [ "投稿を追加する", "投稿を削除する", "ユーザーを利用禁止にする", ] takanory.privileges.privileges = takanory_privileges takanory.privileges.show_privileges()
from user import User, Privileges, Admin user_1 = User("sophie", "kiryakova", 26, "female", "herself") user_1.describe_user() user_1.greet_user() user_2 = Admin("simon", "hoch", 25, "male", "bikes") user_2.describe_user() user_2.privileges.show_privileges() user_2.privileges.set_privileges() user_2.privileges.show_privileges()