class Car: def __init__(self, year, make, speed): self.__year = year self.__make = make self.__speed = speed def set_year(self, year): self.__year = year def set_make(self, make): self.__make = make def set_speed(self, speed): self.__speed = speed def get_year(self): return self.__year def get_make(self): return self.__make def get_speed(self): return self.__speed def accel(self, x): self.__speed = self.__speed + x if(self.__speed > 25): self.__speed = 25 def brake(self,x): self.__speed = self.__speed - x if(self.__speed < 0): self.__speed = 0 def get_speed(self): return self.__speed def main(): year = int(input("Enter the year your vehicle was manufactured: ")) make = raw_input("Enter the make of your vehicle: \n") speed = 0 myCar = Car(year, make, speed) myCar.accel(5) print("Acceleration test 1 speed: {}".format(myCar.get_speed())) myCar.accel(5) print("Acceleration test 2 speed: {}".format(myCar.get_speed())) myCar.accel(5) print("Acceleration test 3 speed: {}".format(myCar.get_speed())) myCar.accel(5) print("Acceleration test 4 speed: {}".format(myCar.get_speed())) myCar.accel(5) print("Acceleration test 5 speed: {}".format(myCar.get_speed())) myCar.brake(5) print("Brake test 1 speed: {}".format(myCar.get_speed())) myCar.brake(5) print("Brake test 2 speed: {}".format(myCar.get_speed())) myCar.brake(5) print("Brake test 3 speed: {}".format(myCar.get_speed())) myCar.brake(5) print("Brake test 4 speed: {}".format(myCar.get_speed())) myCar.brake(5) print("Brake test 5 speed: {}".format(myCar.get_speed())) 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