Python第九章课后习题

这篇博客详细介绍了使用Python编程实现一个餐厅管理系统的九个练习,包括餐馆信息管理、用户登录尝试、权限控制、数据结构应用以及游戏模拟等实际应用场景。通过这些练习,读者可以加深对Python类和模块的理解。
摘要由CSDN通过智能技术生成

9-1 餐馆:

class Restaurant():
	"""docstring for 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,self.cuisine_type)
	def open_restaurant(self):
		print("The restaurant is opening")

restaurant=Restaurant('bobo_restaurant','delicious')
print(restaurant.restaurant_name,restaurant.cuisine_type)
restaurant.describe_restaurant()
restaurant.open_restaurant()
		

运行结果:

9-2 三家餐馆:

restaurant1=Restaurant("lmd_restaurant",'good')
restaurant1.describe_restaurant()
restaurant2=Restaurant("hyk_restaurant",'very good')
restaurant2.describe_restaurant()
restaurant3=Restaurant("kq_restaurant",'so good')
restaurant3.describe_restaurant()

运行结果:

9-3 用户:

class User():
	"""docstring for 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("This is "+self.first_name.title()+' '+self.last_name.lower()+',ages '+str(self.age))
	def greet_user(self):
		print('Hello '+self.first_name.title()+' '+self.last_name.lower())
-
def deal(usr):
	usr.describe_user()
	usr.greet_user()
usr1=User('Ke','sibo',21)
deal(usr1)
usr2=User("Lao",'madong',20)
deal(usr2)
usr3=User("kuang",'qian',20)
deal(usr3)

运行结果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值