Python练习题 9-1 餐馆~9-3用户
来源:互联网 发布:网络婚恋金融诈骗 编辑:程序博客网 时间:2024/05/29 10:03
9-1 餐馆:创建一个名为 Restaurant 的类,其方法init()设置两个属性:
restaurant_name 和 cuisine_type。创建一个名为 describe_restaurant()的方法和一个
名为 open_restaurant()的方法,其中前者打印前述两项信息,而后者打印一条消息,
指出餐馆正在营业。
根据这个类创建一个名为 restaurant 的实例,分别打印其两个属性,再调用前述
两个方法。
9-2 三家餐馆:根据你为完成练习 9-1 而编写的类创建三个实例,并对每个实例调
用方法 describe_restaurant()。
9-3 用户:创建一个名为 User 的类,其中包含属性 first_name 和 last_name,还有
用户简介通常会存储的其他几个属性。在类 User 中定义一个名为 describe_user()的方
法,它打印用户信息摘要;再定义一个名为 greet_user()的方法,它向用户发出个性化
的问候。
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) print(self.cuisine_type) def open_restaurant(self): print('This restaurant is open.')KFC=Restaurant('KFC','fast food')KFC.describe_restaurant()KFC.open_restaurant()print()TS=Restaurant('TS','fire')TS.describe_restaurant()print()QFY=Restaurant('QFY','cheap')QFY.describe_restaurant()print()class User(): def __init__(self,first_name,last_name): self.first_name=first_name self.last_name=last_name def describe_user(self): print(self.first_name+self.last_name) def greet_user(self): print("hey,tony.")Tony=User('Tony','Stark')Tony.describe_user()
阅读全文
0 0
- Python练习题 9-1 餐馆~9-3用户
- Python练习题 10-13 验证用户
- python核心编程 9章练习题
- Python练习题 9-4就餐人数
- Python练习题 9-5尝试登录次数
- Python练习题 9-6冰淇淋小店
- Python练习题3
- Python练习题(3)
- python练习题 3 计时器
- python 练习题1
- Python随笔1-练习题
- Python练习题1
- python练习题 1-10
- python(1)练习题
- Python--day7 练习题1
- Python练习题(1)
- python练习题1
- Python 100练习题[1-10]
- zabbix3.2监控JVM状态
- 有道词典案例
- 20170602-leetcode-211-Add and Search Word
- 搭建《UNIX环境高级编程》环境
- MySQL innoDB索引底层原理详解
- Python练习题 9-1 餐馆~9-3用户
- grep命令
- java--不重复随机数及Arrays.equals()
- 什么是开发框架-- (转载)
- select2的使用
- 要完成的文章
- linux线程池
- 面试题3:数组:二维数组中的查找
- ZJCOJ:qwb与支教(二分)