Advertisement
c0d3dsk1lls

OBJECT ORIENTED PROGRAMMING CodedSkills.net

Jul 30th, 2022
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. #------------------------------------------------------------------------------------------
  2. #engine.py
  3. #-----------------------------------------
  4. from car import Car  #CASE SENSITIVE 'car' and 'Car' are 2 different things.
  5. car_1 = Car("Chevy","Corvette",2022,"blue")
  6. car_2 = Car("Ford","Mustang",2022,"blue")
  7. #------------------------------------------------
  8. #print(car_1.make)
  9. #print(car_1.model)
  10. #print(car_1.year)
  11. #print(car_1.color)
  12. #------------------------------------------------
  13. car_1.drive()
  14. car_1.stop()
  15. #------
  16. car_2.drive()
  17. car_2.stop()
  18. #------------------------------------------------------------------------------------------
  19.  
  20.  
  21.  
  22.  
  23. #=================================
  24.  
  25.  
  26.  
  27. #------------------------------------------------------------------------------------------
  28. #car.py
  29. #-----------------------------------------------
  30. #OBJECT ORIENTED PROGRAMMING
  31. #Create car.py
  32. class Car:
  33.     def __init__(self,make,model,year,color):
  34.         self.make = make
  35.         self.model = model
  36.         self.year = year
  37.         self.color = color
  38. #----------
  39.     def drive(self):
  40.         print("This "+self.model+" is driving")
  41.     def stop(self):
  42.         print("This "+self.model+" is stopped")
  43.  
  44. #-------------------------------
  45. #create yourfile.py and import car.py like this...
  46. #------------------------------------------------------------------------------------------
  47.  
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement