|
| 1 | +"""Functions for calculating steps in exchanging currency. |
| 2 | +
|
| 3 | +Python numbers documentation: https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex |
| 4 | +
|
| 5 | +Overview of exchanging currency when travelling: https://www.compareremit.com/money-transfer-tips/guide-to-exchanging-currency-for-overseas-travel/ |
| 6 | +""" |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +def exchange_money(budget, exchange_rate): |
| 11 | + """ |
| 12 | +
|
| 13 | + :param budget: float - amount of money you are planning to exchange. |
| 14 | + :param exchange_rate: float - unit value of the foreign currency. |
| 15 | + :return: float - exchanged value of the foreign currency you can receive. |
| 16 | + """ |
| 17 | + |
| 18 | + return budget / exchange_rate |
| 19 | + |
| 20 | + |
| 21 | +def get_change(budget, exchanging_value): |
| 22 | + """ |
| 23 | +
|
| 24 | + :param budget: float - amount of money you own. |
| 25 | + :param exchanging_value: float - amount of your money you want to exchange now. |
| 26 | + :return: float - amount left of your starting currency after exchanging. |
| 27 | + """ |
| 28 | + |
| 29 | + return budget - exchanging_value |
| 30 | + |
| 31 | + |
| 32 | +def get_value_of_bills(denomination, number_of_bills): |
| 33 | + """ |
| 34 | +
|
| 35 | + :param denomination: int - the value of a bill. |
| 36 | + :param number_of_bills: int - total number of bills. |
| 37 | + :return: int - calculated value of the bills. |
| 38 | + """ |
| 39 | + |
| 40 | + return denomination * number_of_bills |
| 41 | + |
| 42 | + |
| 43 | +def get_number_of_bills(amount, denomination): |
| 44 | + """ |
| 45 | +
|
| 46 | + :param amount: float - the total starting value. |
| 47 | + :param denomination: int - the value of a single bill. |
| 48 | + :return: int - number of bills that can be obtained from the amount. |
| 49 | + """ |
| 50 | + |
| 51 | + return amount // denomination |
| 52 | + |
| 53 | + |
| 54 | +def get_leftover_of_bills(amount, denomination): |
| 55 | + """ |
| 56 | +
|
| 57 | + :param amount: float - the total starting value. |
| 58 | + :param denomination: int - the value of a single bill. |
| 59 | + :return: float - the amount that is "leftover", given the current denomination. |
| 60 | + """ |
| 61 | + |
| 62 | + return amount % denomination |
| 63 | + |
| 64 | + |
| 65 | +def exchangeable_value(budget, exchange_rate, spread, denomination): |
| 66 | + """ |
| 67 | +
|
| 68 | + :param budget: float - the amount of your money you are planning to exchange. |
| 69 | + :param exchange_rate: float - the unit value of the foreign currency. |
| 70 | + :param spread: int - percentage that is taken as an exchange fee. |
| 71 | + :param denomination: int - the value of a single bill. |
| 72 | + :return: int - maximum value you can get. |
| 73 | + """ |
| 74 | + |
| 75 | + spread_decimal = spread / 100 |
| 76 | + effective_rate = exchange_rate * (1 + spread_decimal) |
| 77 | + exchanged_amount = budget / effective_rate |
| 78 | + leftover = get_leftover_of_bills(exchanged_amount, denomination) |
| 79 | + return int(exchanged_amount - leftover) |
0 commit comments