Skip to content

Commit e85892e

Browse files
committed
implementado a classe Direcao e o atributo valor, metodos virar_a_direita e virar_a_esquerda
1 parent 547599d commit e85892e

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

oo/carro.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,49 @@
9898
>>> carro.calcular_direcao()
9999
'Norte'
100100
"""
101+
NORTE = 'Norte'
102+
SUL = 'Sul'
103+
LESTE = 'Leste'
104+
OESTE = 'OESTE'
105+
class Direcao:
106+
def __init__(self):
107+
self.valor = NORTE
108+
109+
def virar_a_direita(self):
110+
if self.valor == NORTE:
111+
self.valor = LESTE
112+
elif self.valor == LESTE:
113+
self.valor = SUL
114+
elif self.valor == SUL:
115+
self.valor = OESTE
116+
elif self.valor == OESTE:
117+
self.valor = NORTE
118+
119+
120+
121+
def virar_a_esquerda(self):
122+
123+
if self.valor == NORTE:
124+
self.valor = OESTE
125+
elif self.valor == OESTE:
126+
self.valor = SUL
127+
elif self.valor == SUL:
128+
self.valor = LESTE
129+
elif self.valor == LESTE:
130+
self.valor = NORTE
131+
132+
133+
134+
101135

102136

103137
class Motor:
104138
def __init__(self):
105139
self.velocidade = 0
140+
141+
def acelerar(self):
142+
self.velocidade += 1
143+
144+
def frear(self):
145+
self.velocidade -= 2
146+
self.velocidade = max(0, self.velocidade)

0 commit comments

Comments
 (0)