From 9a3aa708c1d5d998e8ebc4fc9c5421c58a482582 Mon Sep 17 00:00:00 2001 From: Tharmabalan Nevaashahan <79234817+Nevaashahan@users.noreply.github.com> Date: Fri, 22 Sep 2023 11:07:35 +0000 Subject: [PATCH] EG_2020_4098 --- travel_cost_calculator.py | 63 ++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/travel_cost_calculator.py b/travel_cost_calculator.py index 27a3d62..aedb3c1 100644 --- a/travel_cost_calculator.py +++ b/travel_cost_calculator.py @@ -1,49 +1,50 @@ -from csv import * -a = {} -b = {} -c = {} +from csv import reader -def lhr(file): +flight_costs = {} +exchange_rates = {} +hotel_rates = {} + +def load_hotel_rates(file): with open(file) as h: - r = reader(h) - for row in r: - a[row[0]] = float(row[1]) + csv_reader = reader(h) + for row in csv_reader: + hotel_rates[row[0]] = float(row[1]) -def ler(file): +def load_exchange_rates(file): with open(file) as e: - r = reader(e) - for row in r: - b[row[0].upper()] = float(row[1]) * 1 + csv_reader = reader(e) + for row in csv_reader: + exchange_rates[row[0].upper()] = float(row[1]) * 1 -def lfr(file): +def load_flight_costs(file): with open(file) as f: - r = reader(f) - for row in r: - c[row[0]] = float(row[1]) + csv_reader = reader(f) + for row in csv_reader: + flight_costs[row[0]] = float(row[1]) def main(): - lhr('data/hotel_rates.csv') - ler('data/exchange_rates.csv') - lfr('data/flight_costs.csv') + load_hotel_rates('data/hotel_rates.csv') + load_exchange_rates('data/exchange_rates.csv') + load_flight_costs('data/flight_costs.csv') - d = input("Enter your destination: ").upper() + destination = input("Enter your final destination: ").upper() - f = c.get(d, 0.0) - h = a.get(d, 0.0) + flight_cost = flight_costs.get(destination, 0.0) + hotel_cost = hotel_rates.get(destination, 0.0) - days = int(input("Enter your stay duration in days: ")) - h *= days - total = f + h + stay_duration = int(input("Enter your current stay duration in days: ")) + hotel_cost *= stay_duration + total_cost = flight_cost + hotel_cost - print(f"Flight cost: USD {f:.2f}") - print(f"Hotel cost for {days} days: USD {h:.2f}") - print(f"Total: USD {total:.2f}") + print(f"Flights total cost: USD {flight_cost:.2f}") + print(f"Hotels total cost for {stay_duration} days: USD {hotel_cost:.2f}") + print(f"Total: USD {total_cost:.2f}") - currency = input(f"Select your currency for final price estimation ({', '.join(b.keys())}): ") + currency = input(f"Select your currency for the final price estimation ({', '.join(exchange_rates.keys())}): ") - p = total * b[currency] - print(f"Total in {currency}: {p:.2f}") + estimated_price = total_cost * exchange_rates[currency] + print(f"Totals in {currency}: {estimated_price:.2f}") if __name__ == "__main__": main()