Create child class Bus that will inherit all of the variables and methods of the Vehicle class

برمجة بايثون | Python programming 


مهني|Professional
  • 2025-03-23

Given:

class Vehicle:

    def __init__(self, name, max_speed, mileage):
        self.name = name
        self.max_speed = max_speed
        self.mileage = mileage
 
 

Create a Bus object that will inherit all of the variables and methods of the parent Vehicle class and display it.

Expected Output:

Vehicle Name: School Volvo Speed: 180 Mileage: 12

 

 

Solution:

--------

class Vehicle:

    def __init__(self, name, max_speed, mileage):
        self.name = name
        self.max_speed = max_speed
        self.mileage = mileage

class Bus(Vehicle):
    pass

School_bus = Bus("School Volvo", 180, 12)
print("Vehicle Name:", School_bus.name, "Speed:", School_bus.max_speed, "Mileage:", School_bus.mileage)
Python

 

هل كان الشرح مفيد؟

avatar
adnan s

 

  • حضوري وجها لوجه في الرياض/السعوديةSA
  • عن بعد/اونلاين
  • شروحات مشابهة

    • برمجة بايثون | Python programming
    • برمجة | Programming
    • برمجة سي شارب | c# programming
    • برمجة جافا | Java programming
    • برمجة بي اتش بي | Php programming
    • برمجة html | Html programming
    • برمجة سي اس اس | Css programming
    • برمجة روبي | Ruby programming
    محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
    ماهو التخصص الذي تبحث عنه؟
    اكتب هنا...