belongs to collection: Python OOP Exercises
Given:
Create a Bus class that inherits from the Vehicle class. Give the capacity argument of Bus.seating_capacity() a default value of 50.
Bus.seating_capacity()
Use the following code for your parent Vehicle class.
class Vehicle: def __init__(self, name, max_speed, mileage): self.name = name self.max_speed = max_speed self.mileage = mileage def seating_capacity(self, capacity): return f"The seating capacity of a {self.name} is {capacity} passengers"
Expected Output:
The seating capacity of a bus is 50 passengers
Hint:
seating_capacity()
Solution:
class Vehicle: def __init__(self, name, max_speed, mileage): self.name = name self.max_speed = max_speed self.mileage = mileage def seating_capacity(self, capacity): return f"The seating capacity of a {self.name} is {capacity} passengers" class Bus(Vehicle): # assign default value to capacity def seating_capacity(self, capacity=50): return super().seating_capacity(capacity=50) School_bus = Bus("School Volvo", 180, 12) print(School_bus.seating_capacity())
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Hint:
seating_capacity()
method definition of a bus class.Solution:
need an explanation for this answer? contact us directly to get an explanation for this answer