-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcar.py
More file actions
36 lines (27 loc) · 830 Bytes
/
car.py
File metadata and controls
36 lines (27 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Car:
count = 0 #Car.count 쓰면 안됨
def __init__(self,type,speed):
self.type=type
self.speed=speed
Car.count +=1 #count만 쓰면 안됨
@classmethod #반드시 있어야함
def get_count(cls): #꼭 이름이 cls가 아니어도 됨
return cls.count #Car.count 써도 됨
def move(self):
print(self.type+"가 "+str(self.speed)+" 속도로 움직입니다.")
def speed_up(self,amount): #그냥 speed 쓰면 안 됨
self.speed+=amount
def speed_down(self,amount):
self.speed-=amount
print(Car.get_count())
c = Car("스포츠카",200)
c.speed_up(10)
c.move()
c.speed_down(10)
c.move()
d = Car("테슬라",200)
d.speed_up(50)
d.move()
d.speed_down(150)
d.move()
print(Car.get_count())