uopspop

Untitled

Nov 6th, 2019
156
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Car:
  2.  
  3.     def __init__(self, speed=0):
  4.         self.speed = speed
  5.         self.odometer = 0
  6.         self.time = 0
  7.  
  8.     def say_state(self):
  9.         print("I'm going {} kph!".format(self.speed))
  10.  
  11.     def accelerate(self):
  12.         self.speed += 5
  13.  
  14.     def brake(self):
  15.         self.speed -= 5
  16.  
  17.     def step(self):
  18.         self.odometer += self.speed
  19.         self.time += 1
  20.  
  21.     def average_speed(self):
  22.         if self.time != 0:
  23.             return self.odometer / self.time
  24.         else:
  25.             pass
  26.  
  27.  
  28. if __name__ == '__main__':
  29.  
  30.     my_car = Car()
  31.     print("I'm a car!")
  32.     while True:
  33.         action = input("What should I do? [A]ccelerate, [B]rake, "
  34.                  "show [O]dometer, or show average [S]peed?").upper()
  35.         if action not in "ABOS" or len(action) != 1:
  36.             print("I don't know how to do that")
  37.             continue
  38.         if action == 'A':
  39.             my_car.accelerate()
  40.         elif action == 'B':
  41.             my_car.brake()
  42.         elif action == 'O':
  43.             print("The car has driven {} kilometers".format(my_car.odometer))
  44.         elif action == 'S':
  45.             print("The car's average speed was {} kph".format(my_car.average_speed()))
  46.         my_car.step()
  47.         my_car.say_state()
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×