#9-1
class Restaurant() :
def __init__( self , _name , _type ):
self.restaurant_name = _name
self.cuisine_type = _type
def describe_restaurant( self ):
print("The name is " , self.restaurant_name )
print("The type is " , self.cuisine_type )
def open_restaurant( self ) :
print( "The restaurant is in business" )
Dongbei = Restaurant( "DongBei" , "Chinese" )
Dongbei.describe_restaurant()
Dongbei.open_restaurant()
#9-3
class User():
def __init__( self , fir , sec , age ):
self.first_name = fir
self.second_name = sec
self.age = age
def describe_user( self ):
print( "name :" , self.first_name , " " , self.second_name )
print( "age :" , self.age )
def greet_user( self ) :
print ("Hello ," ,self.first_name , " " , self.second_name )
zhch = User("zetrue" , 'Lee' , 20 )
tuzha = User("YiFei" ,'Lee' , 20 )
zhch.describe_user()
zhch.greet_user()
tuzha.describe_user()
tuzha.greet_user()
#9-4
class Restaurant() :
def __init__( self , _name , _type , number = 0 ):
self.restaurant_name = _name
self.cuisine_type = _type
self.number_served = number
def describe_restaurant( self ):
print("The name is " , self.restaurant_name )
print("The type is " , self.cuisine_type )
def open_restaurant( self ) :
print( "The restaurant is in business" )
def set_number_served( self , number ):
self.number_served = number
print( self.number_served )
def increment_number_served( self , number ):
self.number_served += 1
print( self.number_served , " and i think the number will be " , number )
Dongbei = Restaurant( "DongBei" , "Chinese" )
Dongbei.describe_restaurant()
Dongbei.open_restaurant()
Dongbei.set_number_served(10)
Dongbei.increment_number_served( 100 )
#9-5
class User():
def __init__( self , fir , sec , age ):
self.first_name = fir
self.second_name = sec
self.age = age
self.login_attempts = 0
def describe_user( self ):
print( "name :" , self.first_name , " " , self.second_name )
print( "age :" , self.age )
def greet_user( self ) :
print ("Hello ," ,self.first_name , " " , self.second_name )
def increment_login_attempts( self ):
self.login_attempts += 1
def reset_login_attempts( self ):
self.login_attempts = 0
def print_attempts( self ):
print( self.login_attempts )
zhch = User("zetrue" , 'Lee' , 20 )
tuzha = User("YiFei" ,'Lee' , 20 )
zhch.describe_user()
zhch.greet_user()
tuzha.describe_user()
tuzha.greet_user()
for i in range(1,9) :
zhch.increment_login_attempts()
zhch.print_attempts()
zhch.reset_login_attempts()
zhch.print_attempts()
#9-6
class IceCreamStand( Restaurant ):
def __init__(self,_name ,_type , number , flavors ):
super().__init__( _name , _type , number )
self.flavors = []
self.flavors = flavors[:]
def IceCreamStand( self ) :
print( self.flavors )
a = ['a','b','v','d']
store = IceCreamStand("ICE" , "desirt" , 100 , a )
store.IceCreamStand()