Python编程:从入门到实践第九章练习9.1

练习9.1

#coding:gbk

class Restaurant():
	def __init__(self, restaurant_name, cuisine_type):
		"""初始化属性"""
		self.restaurant_name = restaurant_name
		self.cuisine_type = cuisine_type
		
	def describe_restaurant(self):
		"""打印名称和类型"""
		print("The restaurant's name is " + self.restaurant_name.title() + " which are specialize in " + self.cuisine_type + ".")
		
	def open_restaurant(self):
		"""打印开业消息"""
		print("The restaurant is opening!")
		
restaurant = Restaurant('john', "french cuisine")

print("\nRestaurant name: " + restaurant.restaurant_name)
print("\nSpecializes in: " + restaurant.cuisine_type)

restaurant.describe_restaurant()
restaurant.open_restaurant()


#9-2三家餐馆
restaurant_john = Restaurant('taylor','salad')
restaurant_john.describe_restaurant()

restaurant_spicy = Restaurant('zhoumapo', 'Sichaun cuisine')
restaurant_spicy.describe_restaurant()

restaurant_kfc = Restaurant('kfc','fast food')
restaurant_kfc.describe_restaurant()


#9-3用户
class User():
	def __init__(self,first_name,last_name,age,location):
		"""设置初始属性"""
		self.first_name = first_name
		self.last_name = last_name
		self.age = age
		self.location = location
		
	def describe_user(self):
		"""打印用户信息摘要"""
		print("\nFirst Name: " + self.first_name.title())
		print("Last Name: " + self.last_name.title())
		print("Age: " + str(self.age))
		print("Location: " + self.location)
		
	def greeter_user(self):
		"""向用户发出个性问候"""
		print("Nice to meet you, " + self.first_name.title() + " " + self.last_name.title() + "!")
		
				
user1 = User('john','su',20,'Amoy')
user2 = User('talor','swift',29,'New York')
user3 = User('avirl','lavigne',36,'Toronto')

user1.describe_user()
user1.greeter_user()
user2.describe_user()
user2.greeter_user()
user3.describe_user()
user3.greeter_user()




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值