import time
class Vehicle:
def __init__(self,m,c):
self.model = m
self.color = c
self.speed = 0
self.meter = 0
def info(self): #infoとゆうメソッドを作成
print("車種 " + self.model)
print("色 " + self.color)
print("速度 {}km/h".format(self.speed))
def set_speed(self, s):
self.speed = s
def move(self):
self.meter += int(self.speed*1000/60/60) #m/毎秒に直す
print("{}は{}m進みました".format(self.model, self.meter))
class AirVehicle(Vehicle): #Vehicleを継承
def __init__(self,m,c,t): #スーパークラスの__init__をオーバーライド
super().__init__(m,c)
self.takeoff = t
def move(self):
self.meter += int(self.speed*1000/60/60)
if self.speed >= self.takeoff:
print("{}は空を{}m飛びました".format(self.model, self.meter))
else:
print("{}は地上を{}m進みました".format(self.model, self.meter))
car = Vehicle("コンパクトカー","red")
car.set_speed(100)
car.info()
aircar = AirVehicle("エアカー","blue",200)
aircar.set_speed(240)
aircar.info()
def main():
for i in range(10):
car.move()
aircar.move()
time.sleep(1)
main()