Advertisement
MeckeOfficial

basic_car_class

Sep 29th, 2021
823
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. class Car:
  2.  
  3.     def __init__(self, color, model, manifacturer):
  4.         self.color = color
  5.         self.model = model
  6.         self.manifacturer = manifacturer
  7.  
  8.     def new_color(self, color):
  9.         self.color = color
  10.  
  11.     def new_model(self, model):
  12.         self.model = model
  13.  
  14.     def new_manifacturer(self, manifacturer):
  15.         self.manifacturer = manifacturer
  16.  
  17.     def get_info(self):
  18.         print(f"""
  19. Color: {self.color}
  20. Model: {self.model}
  21. Manifacturer: {self.manifacturer}
  22. """)
  23.  
  24. car_1 = Car("Red", "M4", "BMW")
  25. car_2 = Car("Blue", "A4", "Audi")
  26. car_3 = Car("Green", "Panamera", "Porsche")
  27.  
  28. car_1.get_info()
  29. car_2.get_info()
  30. car_3.get_info()
  31.  
  32. print("-----------------------")
  33.  
  34. car_1.new_color("Purple")
  35. car_1.get_info()
  36.  
  37. car_2.new_model("R8")
  38. car_2.get_info()
  39.  
  40. car_3.new_manifacturer("Honda")
  41. car_3.get_info()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement