Skip to content

Instantly share code, notes, and snippets.

@sevperez
Created October 8, 2020 07:01
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 sevperez/a8c63c4d1f7a3d881a6d9f0db306a4fd to your computer and use it in GitHub Desktop.
Save sevperez/a8c63c4d1f7a3d881a6d9f0db306a4fd to your computer and use it in GitHub Desktop.
class Car:
def __init__(self, max_speed):
self.max_speed = max_speed
self.current_speed = 0
self.acceleration_rate = 1
def accelerate(self):
if self.current_speed < self.max_speed:
self.current_speed += self.acceleration_rate
if self.current_speed > self.max_speed:
self.current_speed = self.max_speed
def describe_speed(self):
print(f"Current: {self.current_speed}. Max: {self.max_speed}")
class SportsCar(Car):
def __init__(self, max_speed):
super().__init__(max_speed)
self.acceleration_rate = 20
corolla = Car(120)
corolla.accelerate()
corolla.describe_speed() # Current: 5. Max: 120
mustang = SportsCar(165)
mustang.accelerate()
mustang.describe_speed() # Current: 20. Max: 165
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment