-
建立一个汽车类Auto,包括轮胎个数,汽车颜色,车身重量,速度等属性,并通过不同的构造方法创建实例。至少要求 汽车能够加速 减速 停车。 再定义一个小汽车类CarAuto 继承Auto 并添加空调、CD属性,并且重新实现方法覆盖加速、减速的方法
class Auto: def __init__(self, tyre_num=4, color='白', weight='1t', velocity=60): self.tyre_num = tyre_num self.color = color self.weight = weight self.velocity = velocity def speed_up(self, amount): self.velocity += amount def speed_cut(self, amount): self.velocity -= amount def stop(self): self.velocity = 0 class CarAuto(Auto): def __init__(self, air_conditioning='关', cd='关', tyre_num=4, color='白', weight='1t', velocity=60): self.air_conditioning = air_conditioning self.cd = cd super(CarAuto, self).__init__(tyre_num, color, weight, velocity) def speed_up(self, amount): self.velocity += amount*2 def speed_cut(self, amount): self.velocity -= amount*2
-
创建一个Person类,添加一个类字段用来统计Perosn类的创建过的对象的个数
class Person: num = 0 def __init__(self, name): self.name = name Person.num += 1
-
创建一个动物类,拥有属性:性别、年龄、颜色、类型 ,
要求打印这个类的对象的时候以’/XXX的对象: 性别-? 年龄-? 颜色-? 类型-?/’ 的形式来打印
class Animal: def __init__(self, person, sex='雄', age=18, color='蓝', type1='狗'): self.person = person self.sex = sex self.age = age self.color = color self.type1 = type1 def __repr__(self): return f'{self.person}的{self.type1}:{str(Animal(self.person, self.sex, self.age, self.color, self.type1).__dict__)[17:-1]}' cat = Animal('张三', type1='猫') print(cat) # 张三的猫:'sex': '雄', 'age': 18, 'color': '蓝', 'type1': '猫'
-
(不写)写一个圆类, 拥有属性半径、面积和周长;要求获取面积和周长的时候的时候可以根据半径的值把对应的值取到。但是给面积和周长赋值的时候,程序直接崩溃,并且提示改属性不能赋值
-
写一个扑克类, 要求拥有发牌和洗牌的功能(具体的属性和其他功能自己根据实际情况发挥)
-
(尝试)写一个类,其功能是:1.解析指定的歌词文件的内容 2.按时间显示歌词 提示:歌词文件的内容一般是按下面的格式进行存储的。歌词前面对应的是时间,在对应的时间点可以显示对应的歌词
[00:00.20]蓝莲花 [00:00.80]没有什么能够阻挡 [00:06.53]你对自由地向往 [00:11.59]天马行空的生涯 [00:16.53]你的心了无牵挂 [02:11.27][01:50.22][00:21.95]穿过幽暗地岁月 [02:16.51][01:55.46][00:26.83]也曾感到彷徨 [02:21.81][02:00.60][00:32.30]当你低头地瞬间 [02:26.79][02:05.72][00:37.16]才发觉脚下的路 [02:32.17][00:42.69]心中那自由地世界 [02:37.20][00:47.58]如此的清澈高远 [02:42.32][00:52.72]盛开着永不凋零 [02:47.83][00:57.47]蓝莲花
day18作业(1)
最新推荐文章于 2023-11-11 10:46:35 发布