python作业

class Transport(object):

    def __init__(self, space, speak,sport):
        self.space = space
        self.speak = speak
        self.sport = sport
    def talk(self):
        print("它说:“我是 交通工具,我有 占地空间,我 可以运动")

class Traffic(Transport):

    def __init__(self, space, speak, sport,distance,speed,time):
        Transport.__init__(self, space, speak,sport)
        self.distance1 = distance
        self.speed1 = speed
        self.time1 = time

        print(self.distance1, self.speed1, self.time1)

    def distance(self, kilometers):
    # 如果路程在1000米内,选择汽车
    # 如果路程在1000-5000米内,选择轮船
    # 如果路程超过5000米,选择火车
        if kilometers < 1000:
            print("Car")
        elif 1000 <= kilometers <= 5000:
            print("Ship")
        else:
            print("Train")
    # 根据速度,来选择合适的交通工具
    def speed(self, vilous):
    # 如果速度大于199千米/时,选择汽车
    # 如果速度在100-199千米/时内,选择轮船
    # 如果速度在50-99千米/时内,选择火车
        if vilous > 199:
            print("Car")
        if 100 <= vilous <= 199:
            print("Ship")
        if 50 <= vilous <= 99:
            print("Train")
    # 根据时间,来选择合适的交通工具
    def time(self, hour):
    # 如果时间在8小时内,选择汽车
    # 如果时间在8-12小时范围,选择轮船
    # 如果超过12小时,选择火车

        if hour < 8:
            print("Car")
        elif 8 <= hour <= 12:
            print("Ship")
        else:
            print("Train")

Car = Traffic(" "," "," ","500km","200km/h",'"6h"')
Car.talk()
Car.distance(500)
Car.speed(200)
Car.time(6)


Ship = Traffic(" "," "," ","2500km","180km/h",'"11h"')
Ship.talk()
Ship.distance(2500)
Ship.speed(180)
Ship.time(11)

Train = Traffic(" "," "," ","6000km","60km/h",'"16h"')
Train.talk()
Train.distance(6000)
Train.speed(60)
Train.time(16)

你可能感兴趣的:(python作业)