Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #------------------------------------------------------------------------------------------
- #engine.py
- #-----------------------------------------
- from car import Car #CASE SENSITIVE 'car' and 'Car' are 2 different things.
- car_1 = Car("Chevy","Corvette",2022,"blue")
- car_2 = Car("Ford","Mustang",2022,"blue")
- #------------------------------------------------
- #print(car_1.make)
- #print(car_1.model)
- #print(car_1.year)
- #print(car_1.color)
- #------------------------------------------------
- car_1.drive()
- car_1.stop()
- #------
- car_2.drive()
- car_2.stop()
- #------------------------------------------------------------------------------------------
- #=================================
- #------------------------------------------------------------------------------------------
- #car.py
- #-----------------------------------------------
- #OBJECT ORIENTED PROGRAMMING
- #Create car.py
- class Car:
- def __init__(self,make,model,year,color):
- self.make = make
- self.model = model
- self.year = year
- self.color = color
- #----------
- def drive(self):
- print("This "+self.model+" is driving")
- def stop(self):
- print("This "+self.model+" is stopped")
- #-------------------------------
- #create yourfile.py and import car.py like this...
- #------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement