๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
โœ’๏ธ Python Programming/์–ด์„œ์™€ ํŒŒ์ด์ฌ์€ ์ฒ˜์Œ์ด์ง€!_2019 Ver

[์–ด์„œ์™€ ํŒŒ์ด์ฌ์€ ์ฒ˜์Œ์ด์ง€!_2019 Ver] 8์žฅ Lab ๋„์ „๋ฌธ์ œ ํ’€์ด

by A Lim Han 2023. 2. 21.

# 8์žฅ Lab ๋„์ „๋ฌธ์ œ ํ’€์ด

 

 

371p_Lab ๋„์ „ ๋ฌธ์ œ)

class Car:
    def __init__(self, speed=0, gear=1, fuel=0, distance=0, color="white"):
        self.__speed = speed
        self.__gear = gear
        self.__color = color
        self.__fuel = fuel
        self.__distance = distance

    def setSpeed(self, speed):
        self.__speed = speed

    def setGear(self, gear):
        self.__gear = gear

    def setColor(self, color):
        self.__color = color

    def Fuel_efficiency(self, fuel):
        self.__fuel = fuel

    def set_distance(self, distance):
        self.__distance = distance

    def __str__(self):
        return '(์†๋„: %d, ๊ธฐ์–ด: %d, ์—ฐ๋น„: %d, ์ƒ‰์ƒ: %s)\n%dkm ์ฃผํ–‰ ์‹œ ํ•„์š” ์—ฐ๋ฃŒ: %dL' \
            % (self.__speed, self.__gear, self.__fuel, self.__color, self.__distance, (self.__distance / self.__fuel))

myCar = Car()
myCar.setGear(3)
myCar.setSpeed(100)
myCar.Fuel_efficiency(100)
myCar.set_distance(int(input('์ฃผํ–‰ ๊ฑฐ๋ฆฌ: ')))

print('์ž๋™์ฐจ ์ •๋ณด:', myCar)