Advertisement
pacho_the_python

Untitled

Feb 28th, 2022
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. class Cars:
  2.     def __init__(self):
  3.  
  4.         self.production = []
  5.         self.paint_shop_1 = []
  6.         self.paint_shop_2 = []
  7.  
  8.     def make_cars(self, model: str):
  9.         self.production.append(model)
  10.  
  11.     def car_color(self, color: str):
  12.         if color == "red" or color == "blue":
  13.             self.paint_shop_1.append(color)
  14.         elif color == "green" or color == "yellow":
  15.             self.paint_shop_2.append(color)
  16.  
  17.     def __repr__(self):
  18.         result = f"We made total: {len(self.production)} cars. \nRed and blue cars: {len(self.paint_shop_1)}." \
  19.                  f" \nGreen and yellow cars: {len(self.paint_shop_2)}"
  20.         return result
  21.  
  22.  
  23. bmw = Cars()
  24.  
  25. bmw.make_cars("320i")
  26. bmw.car_color("red")
  27.  
  28. bmw.make_cars("520i")
  29. bmw.car_color("blue")
  30.  
  31. bmw.make_cars("430XD")
  32. bmw.car_color("red")
  33.  
  34. bmw.make_cars("M5 Competition")
  35. bmw.car_color("green")
  36.  
  37. bmw.make_cars("M4i50")
  38. bmw.car_color("red")
  39.  
  40. print(bmw)
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement