Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.73 KB | None | 0 0
  1. import random
  2.  
  3. class Cars:
  4.     mileage = 0
  5.     fuel = 100
  6.     def __init__(self, model, economy, color):
  7.         self.model = model
  8.         self.economy = economy
  9.         self.color = color
  10.     def drive(self, destination):
  11.         if
  12.         # while destination:
  13.         #     if self.fuel - self.economy >= 0:
  14.         #         self.mileage += 1
  15.         #         self.fuel -= self.economy
  16.         #         destination -= 1
  17.         #     else:
  18.         #         return 'Not enough fuel to keep driving. You need {} more fuel to finish {} remaining miles'.format(
  19.         #             int(destination * self.economy), destination)
  20.     def distance_left(self):
  21.         return int(self.fuel / self.economy)
  22.         # return str(int(self.fuel * self.economy)) + ' miles we can drive with fuel remaining in cars tank.'
  23.     def fuel_up(self):
  24.         self.fuel = 100
  25.  
  26. cars_dic = {
  27.     'Fiesta': 0.8,
  28.     'Mustang': 2.0,
  29.     'Lanos': 1.1,
  30.     'Jeep': 2.5,
  31.     'Micra': 1.0,
  32.     'Mazda3': 1.5,
  33.     'Matiz': 0.9,
  34.     'BatMobile': 0.5,
  35. }
  36. cars_colors = ['red', 'green', 'orange', 'blue', 'white', 'red', 'pink', 'black', 'grey']
  37. cars_list = []
  38. for car_model, car_economy in cars_dic.items():
  39.     cars_list.append(Cars(car_model, car_economy, random.choice(cars_colors)))
  40.  
  41. for car in cars_list:
  42.     far_going = cars_list[0]
  43.     car.drive(car.distance_left())
  44.     car.fuel_up()
  45.     car.drive(car.distance_left() // 2)
  46.     print('{} crossed {} miles with {} fuel left'.format(car.model, car.mileage, car.fuel))
  47.     if car.mileage > far_going.mileage:
  48.         far_going = car
  49. print('{} crossed {} miles and this is the longest distance out of all cars distances have been tested!'.format(
  50.     far_going.model, far_going.mileage))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement