Skip to content

Instantly share code, notes, and snippets.

@XanderVi
Created June 23, 2018 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XanderVi/d296d3ef7ae489c26f174e258846bdf2 to your computer and use it in GitHub Desktop.
Save XanderVi/d296d3ef7ae489c26f174e258846bdf2 to your computer and use it in GitHub Desktop.
mission Vacation
AIRPLANE_SPEED = 900 # km/h
TRAIN_SPEED = 120 # km/h
CAR_SPEED = 100 # km/h
ONE_MILE = 1.609344 # km
AIRPLANE_PRICE = 100 # per 1h
TRAIN_PRICE = 1 # per 1h
CAR_PRICE = 1.5 # per 1h
class Transport(object):
def travel(self, distance, money):
self.distance = distance
self.money = money
d = self.miles_into_km(distance)
t = self.time(d)
p = self.price(t)
m = self.money_left(p)
return 'Distance: ..., Time: ..., Price: ..., Money left: ...'
def miles_into_km(self, text):
return 'right distance'
def time(self, distance):
raise NotImplementedError()
def price(self, travel_time):
raise NotImplementedError()
def money_left(self, travel_price):
raise 'my money'
class Airplane(Transport):
def time(self, distance):
speed = AIRPLANE_SPEED
return distance
def price(self, travel_time):
travel_price = AIRPLANE_PRICE
return 'price'
class Train(Transport):
def time(self, distance):
speed = AIRPLANE_SPEED
return distance
def price(self, travel_time):
travel_price = AIRPLANE_PRICE
return 'price'
class Car(Transport):
def time(self, distance):
speed = AIRPLANE_SPEED
return distance
def price(self, travel_time):
travel_price = AIRPLANE_PRICE
return 'price'
class BestChoice:
def __init__(self, distance, money, has_time, has_money):
self.distance = distance
self.money = money
self.has_time = has_time
self.has_money = money
def make_choice(self):
first_choice = Airplane()
time_1 = first_choice.time(self.distance)
price_1 = first_choice.price(time_1)
second_choice = Train()
time_2 = second_choice.time(self.distance)
price_2 = second_choice.price(time_2)
third_choice = Car()
time_3 = third_choice.time(self.distance)
price_3 = third_choice.price(time_3)
times = [time_1/self.has_time, time_2/self.has_time, time_3/self.has_time]
prices = [price_1/self.has_money, price_2/self.has_money, price_3/self.has_money]
best_time = min(times)
best_price = min(prices)
best_choice = min(best_time, best_price)
if best_choice <= 1:
if times.index(best_choice) == 0 or prices.index(best_choice) == 0:
return first_choice.travel(self.distance, self.money)
elif times.index(best_choice) == 1 or prices.index(best_choice) == 1:
return second_choice.travel(self.distance, self.money)
return third_choice.travel(self.distance, self.money)
else:
print("You haven't enought time or money to make this trip. Sorry")
person_1 = BestChoice('1860 miles', 21650, 10, 1500)
person_1.make_choice()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment