Untitled

 avatar
unknown
python
3 years ago
1.7 kB
11
Indexable
class Users:
	def __init__(self, first_name, last_name, age, location, gender,\
login_attempts=0):
		self.first_name = first_name.title()
		self.last_name = last_name.title()
		self.age = age
		self.location = location.title()
		self.gender = gender.title()
		self.login_attempts = login_attempts
	def describe_user(self):
		print(f"{self.first_name} {self.last_name}")
		print(f"\t-of {self.gender} gender.")
		print(f"\t-Age is {self.age}.")
		print(f"\t-Lives in {self.location}.")
		print(f"\t-You attempted logins {self.login_attempts} times.\n")
	def greet_user(self):
		print(f"Welcome, {self.first_name}")
	def increment_login_attempts(self):
		self.login_attempts += 1
	def reset_login_attempts(self):
		self.login_attempts = 0
		
class Admin(Users):
	def __init__(self,first_name,last_name, age, location, gender,\
login_attempts=0 ):
		super().__init__(first_name,last_name, age, location, gender,\
login_attempts=0)
		self.privileges = Privileges()
		
class Privileges():
	def __init__(self, privleges=[]):
		self.privleges = privleges
	
	def show_privileges(self):
		print(f"These are the Admin privileges: ")
		for privilege in self.privleges:
			print(f"\t-{privilege}")

amit = Admin('amit','kumar',32,'mumbai','male',4)
amit.privileges = ['can login', 'can approve', 'can reject']
amit.show_privileges()

ERROR MESSAGE
Traceback (most recent call last):
  File "C:\Users\barnw\Desktop\Python crash course\Ch9\ch9exercises.py", line 391, in <module>
    amit.show_privileges()
AttributeError: 'Admin' object has no attribute 'show_privileges'


------------------
(program exited with code: 1)

Press any key to continue . . .
Editor is loading...