Classes and Objects Create a class called Car. The Car class has the following fields: ● color ● model ● manufacturer Instantiate the Car class 5 times and display all properties Modify the properties Can you change the codes without using init function class Car: def __init__(self, color, model, manufacturer): self.color = color self.model = model self.manufacturer = manufacturer def dispData(self): print('Car details: \nColor: ' + self.color + '\nModel: ' + self.model + '\nManufacturer: ' + self.manufacturer)
Classes and Objects
Create a class called Car. The
Car class has the following fields:
● color
● model
● manufacturer
Instantiate the Car class 5 times and display all properties
Modify the properties
Can you change the codes without using init function
class Car:
def __init__(self, color, model, manufacturer):
self.color = color
self.model = model
self.manufacturer = manufacturer
def dispData(self):
print('Car details: \nColor: ' + self.color
+ '\nModel: ' + self.model
+ '\nManufacturer: ' + self.manufacturer)
def main():
mysportscar_1 = Car("Red", "Alto800", "Maruti")
mysportscar_1.dispData()
mysportscar_2 = Car("Blue", "I10NIOS", "Hyundai")
mysportscar_2.dispData()
mysportscar_3 = Car("White", "A8", "Audi")
mysportscar_3.dispData()
mysportscar_4 = Car("Black", "Civic", "Honda")
mysportscar_4.dispData()
mysportscar_5 = Car("Yellow", "Mustang", "Ford")
mysportscar_5.dispData()
main()
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images