W5-C1 作业

本文定义了两个简单的Python类:餐厅类(Restaurant)和用户类(User)。餐厅类包含名称、菜系类型,并能描述餐厅及宣布营业状态。用户类包括姓名和爱好的属性,可以描述用户并向其打招呼。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

9-1

class Restaurant():
	def __init__(self,restaurant_name,cuisine_type):
		self.restaurant_name=restaurant_name
		self.cuisine_type=cuisine_type
	
	def describe_restaurant(self):
		print(self.restaurant_name.title()+" with "+self.cuisine_type.title())
	
	def open_restaurant(self):
		print("The restaurant is open!")

restaurant=Restaurant("fy","western")
restaurant.describe_restaurant()
restaurant.open_restaurant()


9-2

class Restaurant():
	def __init__(self,restaurant_name,cuisine_type):
		self.restaurant_name=restaurant_name
		self.cuisine_type=cuisine_type
	
	def describe_restaurant(self):
		print(self.restaurant_name.title()+" with "+self.cuisine_type.title())
	
	def open_restaurant(self):
		print("The restaurant is open!")

restaurant_1=Restaurant("fy","western")
restaurant_1.describe_restaurant()

restaurant_2=Restaurant("wzy","chinese")
restaurant_2.describe_restaurant()

restaurant_3=Restaurant("xmz","guangdong")
restaurant_3.describe_restaurant()


9-3

class User():
	
	def __init__(self,f_name,l_name,lover):
		self.first_name=f_name
		self.last_name=l_name
		self.lover=lover
	
	def describe_user(self):
		print("Name:"+self.first_name.title()+" "+self.last_name.title()
		+"  "+"Lover:"+self.lover.title())
	
	def greet_user(self):
		print("Hello, my dear "+self.first_name.title()+"!")

user_1=User("bro","fang","cody")
user_1.describe_user()
user_1.greet_user()

user_2=User("cody","zhang","bro")
user_2.describe_user()
user_2.greet_user()

user_3=User("ning","han","henan")
user_3.describe_user()
user_3.greet_user()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值