diff --git a/travel_cost_calculator.py b/travel_cost_calculator.py index 27a3d62..7e2be73 100644 --- a/travel_cost_calculator.py +++ b/travel_cost_calculator.py @@ -1,48 +1,50 @@ + from csv import * -a = {} -b = {} -c = {} +hotelRatesDetails = {} +exchangeRatesDetails = {} +flightRatesDetails = {} -def lhr(file): - with open(file) as h: - r = reader(h) +def ListHotelRates(file): + with open(file) as hotels: + r = reader(hotels) for row in r: - a[row[0]] = float(row[1]) + hotelRatesDetails[row[0]] = float(row[1]) -def ler(file): - with open(file) as e: - r = reader(e) +def ListExchangeRates(file): + with open(file) as exchanges: + r = reader(exchanges) for row in r: - b[row[0].upper()] = float(row[1]) * 1 + exchangeRatesDetails[row[0].upper()] = float(row[1]) * 1 -def lfr(file): - with open(file) as f: - r = reader(f) +def ListFlightRates(file): + with open(file) as flights: + r = reader(flights) for row in r: - c[row[0]] = float(row[1]) + flightRatesDetails[row[0]] = float(row[1]) def main(): - lhr('data/hotel_rates.csv') - ler('data/exchange_rates.csv') - lfr('data/flight_costs.csv') - d = input("Enter your destination: ").upper() + ListHotelRates('data/hotel_rates.csv') + ListExchangeRates('data/exchange_rates.csv') + ListFlightRates('data/flight_costs.csv') + + desination_String = input("Enter your destination: ").upper() - f = c.get(d, 0.0) - h = a.get(d, 0.0) + flightCost = flightRatesDetails.get(desination_String, 0.0) + hotelCost = hotelRatesDetails.get(desination_String, 0.0) - days = int(input("Enter your stay duration in days: ")) - h *= days - total = f + h + stayInDays = int(input("Enter your stay duration in days: ")) + hotelCost *= stayInDays + total = flightRatesDetails + hotelCost print(f"Flight cost: USD {f:.2f}") - print(f"Hotel cost for {days} days: USD {h:.2f}") + print(f"Hotel cost for {stayInDays} days: USD {h:.2f}") print(f"Total: USD {total:.2f}") - currency = input(f"Select your currency for final price estimation ({', '.join(b.keys())}): ") + currency = input(f"Select your currency for final price estimation ({', '.join(exchangeRatesDetails.keys())}): ") - p = total * b[currency] + p = total * exchangeRatesDetails[currency] print(f"Total in {currency}: {p:.2f}") if __name__ == "__main__":