diff --git a/shop_calculator.py b/shop_calculator.py index e5f8b37..77fcfd9 100644 --- a/shop_calculator.py +++ b/shop_calculator.py @@ -1,3 +1,7 @@ +""" +Morawaliyadda M.G.H.S.M +EG/2020/4078 +""" import csv discnts = {} @@ -6,38 +10,62 @@ curr_rates = {} invntry = {} + def ld_discnts(file): + """ + Function of ID discnt + + """ with open(file) as dscnt_file: - r = csv.reader(dscnt_file) - for rw in r: - discnts[rw[0].upper()] = float(rw[1]) + _reader = csv.reader(dscnt_file) + for _rw in _reader: + discnts[_rw[0].upper()] = float(_rw[1]) def ld_taxes(file): + """ + Function of ID taxes + + """ with open(file) as tax_file: - r = csv.reader(tax_file) - for rw in r: + _reader = csv.reader(tax_file) + for rw in _reader: taxes[rw[0].upper()] = float(rw[1]) def ld_prmtns(file): + """ + Function of ID prmtns + + """ with open(file) as prmtn_file: - r = csv.reader(prmtn_file) - for rw in r: + _reader = csv.reader(prmtn_file) + for rw in _reader: prmtns[rw[0]] = float(rw[1]) def ld_curr_rates(file): + """ + Function of ld_curr_rates + + """ with open(file) as currency_file: - r = csv.reader(currency_file) - for rw in r: + _reader = csv.reader(currency_file) + for rw in _reader: curr_rates[rw[0].upper()] = float(rw[1]) def ld_invntry(file): + """ + Function of ld_invntry + + """ with open(file) as inv_file: - r = csv.reader(inv_file) - for rw in r: + _reader = csv.reader(inv_file) + for rw in _reader: invntry[rw[0].upper()] = int(rw[1]) def main(): + """ + main function + """ ld_discnts('data/discounts.csv') ld_taxes('data/tax_rates.csv') ld_prmtns('data/promotions.csv') @@ -61,11 +89,11 @@ def main(): if promo: qty = qty - (qty // promo) dscnt = discnts.get(itm, 0) - price = 1.0 + price = 1.0 dscntd_price = price - (price * dscnt) item_price = dscntd_price * qty total_price_usd += item_price - invntry[itm] -= qty + invntry[itm] -= qty available_states = list(taxes.keys()) print("Enter your state. Available states are: ", ', '.join(available_states)) @@ -87,7 +115,9 @@ def main(): print(f"Total: USD {final_price_usd:.2f}") available_currencies = list(curr_rates.keys()) - selected_currency = input("Select currency for payment ({}): ".format(', '.join(available_currencies))) + selected_currency = input( + "Select currency for payment ({}): ".format(', '.join(available_currencies)) + ) final_price_currency = final_price_usd * curr_rates.get(selected_currency) diff --git a/travel_cost_calculator.py b/travel_cost_calculator.py index 27a3d62..b805171 100644 --- a/travel_cost_calculator.py +++ b/travel_cost_calculator.py @@ -1,49 +1,69 @@ +""" +Morawaliyadda M.G.H.S.M +EG/2020/4078 +""" from csv import * a = {} b = {} c = {} -def lhr(file): - with open(file) as h: - r = reader(h) - for row in r: +def lhr(file): + """ + Function of Ihr + + """ + with open(file) as _hours: + _reader = reader(_hours) + for row in _reader: a[row[0]] = float(row[1]) def ler(file): + """ + Function of ler + + """ with open(file) as e: - r = reader(e) - for row in r: + _reader = reader(e) + for row in _reader: b[row[0].upper()] = float(row[1]) * 1 def lfr(file): + """ + Function of lfr + + """ with open(file) as f: - r = reader(f) - for row in r: + _reader = reader(f) + for row in _reader: c[row[0]] = float(row[1]) def main(): + """ + Main Function + + """ lhr('data/hotel_rates.csv') ler('data/exchange_rates.csv') lfr('data/flight_costs.csv') - d = input("Enter your destination: ").upper() + _days = input("Enter your destination: ").upper() - f = c.get(d, 0.0) - h = a.get(d, 0.0) + f = c.get(_days, 0.0) + _hours = a.get(_days, 0.0) days = int(input("Enter your stay duration in days: ")) - h *= days - total = f + h + _hours *= days + total = f + _hours print(f"Flight cost: USD {f:.2f}") - print(f"Hotel cost for {days} days: USD {h:.2f}") + print(f"Hotel cost for {days} days: USD {_hours:.2f}") print(f"Total: USD {total:.2f}") currency = input(f"Select your currency for final price estimation ({', '.join(b.keys())}): ") - p = total * b[currency] - print(f"Total in {currency}: {p:.2f}") + new = total * b[currency] + print(f"Total in {currency}: {new:.2f}") if __name__ == "__main__": main()