Ynns

Python 3 본문

카테고리 없음

Python 3

yunassnn 2019. 10. 28. 14:50
class Car :
    speed = 0

    def upSpeed(self, value):
        self.speed=self.speed+value

    def downSpeed(self, value):
        self.speed=self.speed-value

class Sedan(Car):
    seatNum=0 #5

    def getSeatNum(self):
        return self.seatNum

class Truck(Car):
    capacity=0 #50

    def getCapacity(self):
        return self.capacity

#인스턴스화(main)
sedan1, truck1 = None, None

sedan1=Sedan()
truck1=Truck()

sedan1.upSpeed(100)
truck1.upSpeed(10)

sedan1.seatNum=5
truck1.capacity=50

print("승용차의 속도는 %d km, 좌석수는 %d 개입니다" % (sedan1.speed, sedan1.getSeatNum()))
print("트럭의 속도는 %d km, 트럭의 총 중량은 %d 톤입니다" % (truck1.speed, truck1.getCapacity()))
Comments