Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- class Cars:
- mileage = 0
- fuel = 100
- def __init__(self, model, economy, color):
- self.model = model
- self.economy = economy
- self.color = color
- def drive(self, destination):
- if
- # while destination:
- # if self.fuel - self.economy >= 0:
- # self.mileage += 1
- # self.fuel -= self.economy
- # destination -= 1
- # else:
- # return 'Not enough fuel to keep driving. You need {} more fuel to finish {} remaining miles'.format(
- # int(destination * self.economy), destination)
- def distance_left(self):
- return int(self.fuel / self.economy)
- # return str(int(self.fuel * self.economy)) + ' miles we can drive with fuel remaining in cars tank.'
- def fuel_up(self):
- self.fuel = 100
- cars_dic = {
- 'Fiesta': 0.8,
- 'Mustang': 2.0,
- 'Lanos': 1.1,
- 'Jeep': 2.5,
- 'Micra': 1.0,
- 'Mazda3': 1.5,
- 'Matiz': 0.9,
- 'BatMobile': 0.5,
- }
- cars_colors = ['red', 'green', 'orange', 'blue', 'white', 'red', 'pink', 'black', 'grey']
- cars_list = []
- for car_model, car_economy in cars_dic.items():
- cars_list.append(Cars(car_model, car_economy, random.choice(cars_colors)))
- for car in cars_list:
- far_going = cars_list[0]
- car.drive(car.distance_left())
- car.fuel_up()
- car.drive(car.distance_left() // 2)
- print('{} crossed {} miles with {} fuel left'.format(car.model, car.mileage, car.fuel))
- if car.mileage > far_going.mileage:
- far_going = car
- print('{} crossed {} miles and this is the longest distance out of all cars distances have been tested!'.format(
- far_going.model, far_going.mileage))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement