class Car: yearModel = 0 make = "" speed = 0 def __init__(self,yearModel,make,speed): self.yearModel = yearModel self.make = make self.speed = speed def accelerate(self): self.speed = self.speed + 5 def brake(self): self.speed = self.speed - 5 def getyearModel(self): return self.yearModel def getcarMake(self): return self.carMake def getspeed(self): return self.speed def main(): yearModel = input("What is the model year of the vehicle? \n") carMake = raw_input("What is the make of the vehicle? \n") speed = 0 carIn = Car(yearModel,carMake,speed) for accelerate in range (1,6): carIn.accelerate() print("Acceleration Test {} = {} MPH.".format(accelerate, carIn.getspeed())) for brake in range (1,6): carIn.brake() print("Brake Test {} = {} MPH.".format(brake, carIn.getspeed())) main()
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