Skip to content

Instantly share code, notes, and snippets.

@ysnerdem
Last active October 31, 2017 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ysnerdem/0f24a5d1e8c5abdc56a7e44e9c313924 to your computer and use it in GitHub Desktop.
Save ysnerdem/0f24a5d1e8c5abdc56a7e44e9c313924 to your computer and use it in GitHub Desktop.
class Car:
def __init__(self):
self.make = "Lamborghini"
self.model = "Gallardo"
self.car_segment = "supercars"
self.year = "2013"
self.body_style = "coupe"
self.top_speed = 325
self.speed = 0
self.gas = 0
def show_room(self):
print("Make:", self.make, "Model:", self.model, "Car segment:", self.car_segment,
"Year:", self.year, "Boddy style:", self.body_style)
def speedrun(self):
self.gas += 1
if self.speed < self.top_speed and self.gas < 3:
self.speed += 60
print(self.speed, "km/h")
elif self.speed < self.top_speed and self.gas < 5:
self.speed += 45
print(self.speed, "km/h")
elif self.speed < self.top_speed and self.gas < 8:
self.speed += 30
print(self.speed, "km/h")
elif self.speed < self.top_speed and self.gas >= 8:
self.speed += 25
print(self.speed, "km/h")
elif self.speed == self.top_speed:
print("you are at your highest speed", self.speed)
else:
print("uncomment action")
def brake(self):
if self.speed > 0:
self.speed -= 50
if self.speed == 0:
print("the car stopped")
car = Car()
while True:
print("Choose action**")
print("(q)Show car")
print("(w)Gas")
print("(s)brake")
action = input("Enter action:")
if action == "q":
car.show_room()
elif action == "w":
car.speedrun()
elif action == "s":
car.brake()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment