Osio 2. Luku 3
single
Challenge: Creating a Vehicle Hierarchy
Pyyhkäise näyttääksesi valikon
Tehtävä
Pyyhkäise aloittaaksesi koodauksen
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>
Ratkaisu
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 2. Luku 3
single
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme