Solución
solution.tsTypeScript
BASE_FARE = 2.50
RATE_PER_KM = 1.20
NIGHT_SURCHARGE_MULTIPLIER = 1.50
EXTRA_PASSENGER_FEE = 0.30
PASSENGER_THRESHOLD = 4
MINIMUM_FARE = 5.00
NIGHT_START_HOUR = 22
NIGHT_END_HOUR = 6
def is_night_time(hour: int) -> bool:
return hour >= NIGHT_START_HOUR or hour <= NIGHT_END_HOUR
def calculate_distance_cost(distance: float, hour:int) -> float:
cost = 0.0
rate = RATE_PER_KM
if is_night_time(hour):
rate *= NIGHT_SURCHARGE_MULTIPLIER
cost = rate * distance
return cost
def calculate_extra_passengers_fee(passengers: int) -> float:
cost = 0.0
if passengers > PASSENGER_THRESHOLD:
extra_passengers = passengers - PASSENGER_THRESHOLD
cost = extra_passengers * EXTRA_PASSENGER_FEE
return cost
def calculate_taxi_fare(distance: float, hour: int, passengers: int) -> float:
distance_cost = calculate_distance_cost(distance, hour)
extra_fee = calculate_extra_passengers_fee(passengers)
total_fare = BASE_FARE + distance_cost + extra_fee
cost = max(total_fare, MINIMUM_FARE)
return cost0respuestas