i人生总会有让你不舒服的事,不要在它上纠结,把时间浪费在你想做的事上。
第九章
class Restaruarant():
def __init__(self,restaurant_name,cuisine_type):
self.restaurant_name=restaurant_name
self.cuisine_type=cuisine_type
def describe_restaurant(self):
print("The cuisine_type is: "+self.cuisine_type)
print("The restaurant_name is: "+self.restaurant_name)
def open_restaurant(self):
print("We are in business.")
R1=Restaruarant('客来','东北菜')
print(R1.restaurant_name+" is good at "+R1.cuisine_type+".")
R1.describe_restaurant()
R1.open_restaurant()
出错点:
1、__init__()两边的下划线是两个!
2、两个方法里忘记了加self
class Restaruarant():
def __init__(self,restaurant_name,cuisine_type):
self.restaurant_name=restaurant_name
self.cuisine_type=cuisine_type
def describe_restaurant(self):
print("The cuisine_type is: "+self.cuisine_type)
print("The restaurant_name is: "+self.restaurant_name)
def open_restaurant(self):
print("We are in business.")
R1=Restaruarant('客来','东北菜')
print(R1.restaurant_name+" is good at "+R1.cuisine_type+".")
R1.describe_restaurant()
R1.open_restaurant()
print("\n")
R2=Restaruarant('红旗','东北菜')
R3=Restaruarant('山西','刀削面')
R4=Restaruarant('西北','兰州拉面')
R2.describe_restaurant()
R2.open_restaurant()
R3.describe_restaurant()
R3.open_restaurant()
R4.describe_restaurant()
R4.open_restaurant()
class User():
def __init__(self,first_name,last_name,age):
self.first_name=first_name
self.last_name=last_name
self.age=age
def describe_user(self):
print("first name is "+self.first_name)
print("last name is "+self.last_name)
print("age is "+str(self.age))
def greet_user(self):
full_name=self.first_name+" "+self.last_name
print("Welcome you ,"+full_name+" ,have a nice day .")
user1=User('张','宸宸',23)
user1.greet_user()
user1.describe_user()
user2=User('王','舍',24)
user2.greet_user()
user2.describe_user()
user3=User('肖','大在',83)
user3.greet_user()
user3.describe_user()
【注意】每个属性前面都是要加self.的。
class Restaruarant(