Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 32 additions & 31 deletions travel_cost_calculator.py
Original file line number Diff line number Diff line change
@@ -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()