9-1
class Restautant():
def __init__(self, restaurant_name, cuisine_type):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
print('Name: '+self.restaurant_name)
print('Type: '+self.cuisine_type)
def open_restaurant(self):
print(self.restaurant_name+' is open')
A = Restautant('B', 'C')
D = Restautant('E', 'F')
A.describe_restaurant()
D.describe_restaurant()
A.open_restaurant()
D.open_restaurant()
9-2
class Restautant():
def __init__(self, restaurant_name, cuisine_type):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
print('Name: '+self.restaurant_name)
print('Type: '+self.cuisine_type)
def open_restaurant(self):
print(self.restaurant_name+' is open')
A = Restautant('B', 'C')
D = Restautant('E', 'F')
G = Restautant('H', 'I')
A.describe_restaurant()
D.describe_restaurant()
G.describe_restaurant()
9-3
class User():
def __init__(self, first_name, last_name, age):
self.first_name = first_name.title()
self.last_name = last_name.title()
self.age = age
def describe_user(self):
print('Name: '+self.first_name+' '+self.last_name)
print('Age: '+str(self.age))
def greet_user(self):
print('Hello, '+self.first_name+' '+self.last_name+'!')
A = User('B', 'C', 10)
D = User('E', 'F', 20)
A.describe_user()
D.describe_user()
A.greet_user()
D.greet_user()
9-4
class Restautant():
def __init__(self, restaurant_name, cuisine_type, number_served=0):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
print('Name: '+self.restaurant_name)
print('Type: '+self.cuisine_type)
def open_restaurant(self):
print(self.restaurant_name+' is open')
def set_number_served(self, number_served):
self.number_served = number_served
def increment_number_served(self, number_served):
self.number_served += number_served
restaurant = Restautant('A', 'B')
restaurant.number_served = 7
print(restaurant.number_served)
restaurant.set_number_served(8)
print(restaurant.number_served)
restaurant.increment_number_served(9)
print(restaurant.number_served)
9-5
class User():
def __init__(self, first_name, last_name, age, login_attempts=0):
self.first_name = first_name.title()
self.last_name = last_name.title()
self.age = age
self.login_attempts = login_attempts
def describe_user(self):
print('Name: '+self.first_name+' '+self.last_name)
print('Age: '+str(self.age))
def greet_user(self):
print('Hello, '+self.first_name+' '+self.last_name+'!')
def increment_login_attempts(self):
self.login_attempts += 1
def reset_login_attempts(self):
self.login_attempts = 0
user = User('A', 'B', 7)
user.increment_login_attempts()
user.increment_login_attempts()
user.increment_login_attempts()
user.increment_login_attempts()
print(user.login_attempts)
user.reset_login_attempts()
print(user.login_attempts)
9-6
class Restautant():
def __init__(self, restaurant_name, cuisine_type, number_served=0):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
print('Name: '+self.restaurant_name)
print('Type: '+self.cuisine_type)
def open_restaurant(self):
print(self.restaurant_name+' is open')
def set_number_served(self, number_served):
self.number_served = number_served
def increment_number_served(self, number_served):
self.number_served += number_served
class IceCreamStand(Restautant):
def __init__(self, restaurant_name, cuisine_type, number_served=0, flavors=[]):
super().__init__(restaurant_name, cuisine_type, number_served)
self.flavors = flavors
def describe_icecreamstand(self):
print('Our stand have: ', end='')
for flavor in flavors:
print(flavor, end=' ')
print()
flavors =['A', 'B', 'C']
icecreamstand = IceCreamStand('D', 'E', 0, flavors)
icecreamstand.describe_icecreamstand()
9-7
class User():
def __init__(self, first_name, last_name, age, login_attempts=0):
self.first_name = first_name.title()
self.last_name = last_name.title()
self.age = age
self.login_attempts = login_attempts
def describe_user(self):
print('Name: '+self.first_name+' '+self.last_name)
print('Age: '+str(self.age))
def greet_user(self):
print('Hello, '+self.first_name+' '+self.last_name+'!')
def increment_login_attempts(self):
self.login_attempts += 1
def reset_login_attempts(self):
self.login_attempts = 0
class Admin(User):
def __init__(self, first_name, last_name, age, login_attempts=0, privileges=''):
super().__init__(first_name, last_name, age, login_attempts)
self.privileges = privileges
def show_privileges(self):
print('Privileges: '+self.privileges)
admin = Admin('A', 'B', 3, 0, 'can add post')
admin.show_privileges()
9-8
class User():
def __init__(self, first_name, last_name, age, login_attempts=0):
self.first_name = first_name.title()
self.last_name = last_name.title()
self.age = age
self.login_attempts = login_attempts
def describe_user(self):
print('Name: '+self.first_name+' '+self.last_name)
print('Age: '+str(self.age))
def greet_user(self):
print('Hello, '+self.first_name+' '+self.last_name+'!')
def increment_login_attempts(self):
self.login_attempts += 1
def reset_login_attempts(self):
self.login_attempts = 0
class Privileges():
def __init__(self):
self.privileges = ['can add post', 'can delete post', 'can ban user']
def show_privileges(self):
print('Privileges: ', end='')
for privilege in self.privileges:
print(privilege, end=', ')
print()
class Admin(User):
def __init__(self, first_name, last_name, age, login_attempts, privileges):
super().__init__(first_name, last_name, age, login_attempts)
self.privileges = privileges
privileges = Privileges()
admin = Admin('A', 'B', 3, 0, privileges)
admin.privileges.show_privileges()