2019-08-11day15作业

  1. 建立一个汽车类Auto,包括轮胎个数,汽车颜色,车身重量,速度等属性,并通过不同的构造方法创建实例。至少要求 汽车能够加速 减速 停车。 再定义一个小汽车类CarAuto 继承Auto 并添加空调、CD属性,并且重新实现方法覆盖加速、减速的方法
class Auto:
    bdef __init__(self, tyre, color, weight, speed):
        self.tyre = tyre
        self.color = color
        self.weight = weight
        self.speed = speed
        
    def accelerate(self):
        print('speed is up to', speed+30)
    def slow_down(self):
        print('speed is reduce to', speed-30)
    def car_stop(self):
        print('the car is stopped')
        
class CarAuto(Auto):
    def __init__(self, air_condition, cd):
        super(CarAuto, self).__init__()
        self.air_condition = air_condition
        self.cd = cd
        
    def accelerate(self):
        print('speed is up to', speed+20)
    def slow_down(self):
        print('speed is reduce to', speed-20)
  1. 创建一个Person类,添加一个类字段用来统计Perosn类的对象的个数
class Perosn:
    count = 0
    def __init__(self):
        Person.count += 1
    def __del__(self):
        Person.count -= 1
  1. 创建一个动物类,拥有属性:性别、年龄、颜色、类型 ,
class Animal:
    def __init__(self, gender, age, color, species):
        self._gender = gender
        self._age = age
        self._color = color
        self._species = species
    
    @property
    def gender(self):
        return Animal.__name__+'的对象:性别-'+self._gender
    @property
    def age(self):
        return Animal.__name__+'的对象:年龄-'+str(self._age)
    @property
    def color(self):
        return Animal.__name__+'的对象:颜色-'+self._color
    @property
    def species(self):
        return Animal.__name__+'的对象:类型-'+self._species

要求打印这个类的对象的时候以'/XXX的对象: 性别-? 年龄-? 颜色-? 类型-?/' 的形式来打印

  1. 写一个圆类, 拥有属性半径、面积和周长;要求获取面积和周长的时候的时候可以根据半径的值把对应的值取到。但是给面积和周长赋值的时候,程序直接崩溃,并且提示改属性不能赋值
class ReadonlyError(Exception):
    def __str__(self):
        return '该属性不能赋值'


class Circle:
    def __init__(self):
        self.redius = redius
        self._area = 3.1415926*self.redius**2
        self._girth = 2*3.1415926*redius
    
    @property
    def area(self):
        return self._area
    @area.setter
    def area(self, value):
        raise ReadonlyError
    
    @property
    def girth(self):
        return self._girth
    
    @girth.setter
    def girth(self, value):
        raise ReadonlyError
        
  1. 写一个扑克类, 要求拥有发牌和洗牌的功能(具体的属性和其他功能自己根据实际情况发挥)
import colorama
print(colorama.Fore.MAGENTA)
import random


class Poker:
    poker_ = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'A', 'J', 'K', 'Q']
    color_ = ['♠', '♣', '♥', '♦']
    card = ['king', 'kinglet']

    players = []

    def __init__(self, n: int):
        self.n = n
        self.players = Poker.players

    def shuffle(self):
        for color in self.color_:
            for poker in self.poker_:
                self.card.append((color, poker))
        random.shuffle(self.card)

    def deal(self):

        if not self.players:
            for i in range(self.n):
                self.players.append([])
        else:
            for i in range(self.n):
                self.players[i].clear()

        for i in range(self.n):
            for j in range(3):
                self.players[i].append(self.card.pop())
        if len(self.card) < 3*self.n:
            self.shuffle()
            
  1. (尝试)写一个类,其功能是: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]蓝莲花  
    
import time


class Lyrics:
    def __init__(self):
        self.ly1 = '蓝莲花'
        self.ly2 = '没有什么能够阻挡'
        self.ly3 = '你对自由的向往'
        self.ly4 = '天马行空的生涯'
        self.ly5 = '你的心了无牵挂'
        self.ly6 = '穿过幽暗的岁月'
        self.ly7 = '也曾感到彷徨'
        self.ly8 = '当你低头的瞬间'
        self.ly9 = '才发现脚下的路'
        self.ly10 = '心中那自由的世界'
        self.ly11 = '如此的清澈高远'
        self.ly12 = '盛开着永不凋零'


    def time_shower(self, t_):
        if t_ < 10:
            return '[00:0%.2f]' % t_
        elif t_ < 60:
            return '[00:%.2f]' % t_
        else:
            if t_ % 60 < 10:
                return '[0%d:0%.2f]' % (t_ // 60, t_ % 60)
            else:
                return '[0%d:%.2f]' % (t_ // 60, t_ % 60)

    def show(self):
        t0 = time.clock()
        t1 = time.clock()
        while t1 < 167.83:
            t1 = time.clock()
            time.sleep(0.2)
            if (t1 - t0 < 0.2 or 52.72 < t1 - t0 < 57.47 or 162.32 < t1 - t0 < 167.83):
                print(self.time_shower(t1), self.ly1)
            if 0.2 < t1 - t0 < 0.8:
                print(self.time_shower(t1), self.ly2)
            if 0.8 < t1 - t0 < 6.53:
                print(self.time_shower(t1), self.ly3)
            if 6.53 < t1 - t0 < 11.59:
                print(self.time_shower(t1), self.ly4)
            if 11.59 < t1 - t0 < 16.53:
                print(self.time_shower(t1), self.ly5)
            if (16.53 < t1 - t0 < 21.95 or 57.47 < t1 - t0 < 110.22 or 125.72 < t1 - t0 < 131.27):
                print(self.time_shower(t1), self.ly6)
            if (21.95 < t1 - t0 < 26.83 or 110.22 < t1 - t0 < 115.46 or 131.27 < t1 - t0 < 136.51):
                print(self.time_shower(t1), self.ly7)
            if (26.83 < t1 - t0 < 32.30 or 115.46 < t1 - t0 < 120.60 or 136.51 < t1 - t0 < 141.81):
                print(self.time_shower(t1), self.ly8)
            if (32.30 < t1 - t0 < 37.16 or 120.60 < t1 - t0 < 125.72 or 141.81 < t1 - t0 < 146.79):
                print(self.time_shower(t1), self.ly9)
            if (37.16 < t1 - t0 < 42.69 or 146.79 < t1 - t0 < 152.17):
                print(self.time_shower(t1), self.ly10)
            if (42.69 < t1 - t0 < 47.58 or 152.17 < t1 - t0 < 157.20):
                print(self.time_shower(t1), self.ly11)
            if (47.58 < t1 - t0 < 52.72 or 157.20 < t1 - t0 < 162.32):
                print(self.time_shower(t1), self.ly12)
        

你可能感兴趣的:(2019-08-11day15作业)