Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/oop/oop1.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,25 @@
# pass
#
# Put a comment noting which class is the base class

#base class "Vehicle"
class Vehicle:
pass

class FlightVehicle(Vehicle):
pass

class Airplane(FlightVehicle):
pass

class Starship(FlightVehicle):
pass


class GroundVehicle:
pass
class Car(GroundVehicle):
pass

class Motorcycle(GroundVehicle):
pass
18 changes: 16 additions & 2 deletions src/oop/oop2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@
# object is constructed.

class GroundVehicle():
def __init__(self, num_wheels):
def __init__(self, num_wheels = 4):
self.num_wheels = num_wheels
def drive(self):
return "vroooom"

# TODO


class Motorcycle(GroundVehicle):
def __init__(self, num_wheels=2):
super().__init__(num_wheels=num_wheels)

def drive(self):
return "BRAAAP!!"
# Subclass Motorcycle from GroundVehicle.
#
# Make it so when you instantiate a Motorcycle, it automatically sets the number
Expand All @@ -26,6 +33,13 @@ def __init__(self, num_wheels):
GroundVehicle(),
Motorcycle(),
]
print(vehicles[0].drive())
print(vehicles[1].drive())
print(vehicles[2].drive())
print(f' The number of wheels on a motorcylce is {vehicles[2].num_wheels}')
print(vehicles[3].drive())
print(vehicles[4].drive())


# Go through the vehicles list and print the result of calling drive() on each.

Expand Down