#Create an object class class Car: #Give the car/object some attributes def __init__(self, yearModel, carMake, speed): self.__yearModel = yearModel self.__carMake = carMake self.__speed = 0 def getyearModel(self): return self.__yearModel def getcarMake(self): return self.__carMake def getspeed(self): return self.__speed #Model accelerate and brake behaviors def accelerate(self): self.__speed += 5 def brake(self): self.__speed -= 5 yearModel = input() carMake = raw_input() speed = 0 myCar = Car(yearModel, carMake, speed) #Request user input print("What is the 4 digit model year of the car being tested?") print("The model year of the car being tested is: {}\n".format(yearModel)) print("What is the name of the manufacturer of the car being tested?") print("The manufacturer of the car being tested is: {}\n".format(carMake)) #User enters their car data print("The car's test will begin at 0 MPH, it will then accelerate in 5 MPH increments until reaching 25 MPH.\nUpon reaching 25 MPH, it will begin braking in 5 MPH increments until reaching 0 MPH.\n") #Report status for accelerate in range (1,6): myCar.accelerate() print("The status of the acceleration test at increment {}: {} MPH".format(accelerate, myCar.getspeed())) for brake in range (1,6): myCar.brake() print("The status of the braking test at increment {}: {} MPH".format(brake, myCar.getspeed())) #End
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