Abschnitt 2. Kapitel 3
single
Challenge: Creating a Vehicle Hierarchy
Swipe um das Menü anzuzeigen
Aufgabe
Wischen, um mit dem Codieren zu beginnen
Define a class hierarchy for different types of vehicles:
- Create a base class named
Vehiclewith an__init__method that takesbrandandspeedas arguments. - Add a method called
get_infotoVehiclethat returns the brand and speed. - Create a subclass
Carthat inherits fromVehicleand adds adoorsattribute. - Create a subclass
Bikethat inherits fromVehicleand adds atypeattribute (such as'mountain'or'road'). - Override the
get_infomethod in bothCarandBiketo include their extra data (doorsfor cars,typefor bikes).
Expected output format:
# Vehicle
Brand: <brand>, Speed: <speed>
# Car
Brand: <brand>, Speed: <speed>, Doors: <doors>
# Bike
Brand: <brand>, Speed: <speed>, Type: <type>
Lösung
War alles klar?
Danke für Ihr Feedback!
Abschnitt 2. Kapitel 3
single
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen