#Create an object class class Car: #Give the car attributes def __init__(self, yearModel, carMake, speed): self.__yearModel = yearModel self.__carMake = carMake self.__speed = speed #Model accelerate and brake behaviors def accelerate(self): self.__speed = self.__speed + 5 def brake(self): self.__speed = self.__speed - 5 def setYearModel(self, yearModel): self.__yearModel = yearModel def setCarMake(self, carMake): self.__carMake = carMake def setSpeed(self, speed): self.__speed = speed def getYearModel(self): return self.__yearModel def getCarMake(self): return self.__carMake def getSpeed(self): return self.__speed #Access Data def get_type(self): print("Car") #Report status def status(self): print("The speed of the {} {} is currently {} MPH".format(self.__yearModel,self.__carMake,self.__speed,)) #enter car info yearModel=input("What is the model year of your car?\n") carMake=raw_input("What is your car's make?\n") speed = 0 print("The car is a {} {} travelling at {} MPH.\n".format(yearModel, carMake, speed)) #Call the incremental speed reports myCar=Car(yearModel, carMake, 0) myCar.accelerate() myCar.status() myCar.accelerate() myCar.status() myCar.accelerate() myCar.status() myCar.accelerate() myCar.status() myCar.accelerate() myCar.status() myCar.brake() myCar.status() myCar.brake() myCar.status() myCar.brake() myCar.status() myCar.brake() myCar.status() myCar.brake() myCar.status()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question