|
6 | 6 | """ |
7 | 7 |
|
8 | 8 | def exchange_money(budget, exchange_rate): |
9 | | - """ |
| 9 | + """Calculate estimated value after exchange. |
| 10 | +
|
| 11 | + Parameters: |
| 12 | + budget (float): Tthe amount of money you are planning to exchange. |
| 13 | + exchange_rate (float): The unit value of the foreign currency. |
| 14 | +
|
| 15 | + Returns: |
| 16 | + float: The exchanged value of the foreign currency you can receive. |
| 17 | +
|
| 18 | + Examples: |
| 19 | + >>> exchange_money(127.5, 1.2) |
| 20 | + 106.25 |
| 21 | +
|
| 22 | + >>> exchange_money(200, 1.10) |
| 23 | + 181.82 |
| 24 | +
|
| 25 | + This function calculates and returns the (estimated) value of the exchanged currency. |
10 | 26 |
|
11 | | - :param budget: float - amount of money you are planning to exchange. |
12 | | - :param exchange_rate: float - unit value of the foreign currency. |
13 | | - :return: float - exchanged value of the foreign currency you can receive. |
14 | 27 | """ |
15 | 28 |
|
16 | 29 | return budget / exchange_rate |
17 | 30 |
|
18 | 31 |
|
19 | 32 | def get_change(budget, exchanging_value): |
20 | | - """ |
| 33 | + """Calculate currency left after an exchange. |
| 34 | +
|
| 35 | + Parameters: |
| 36 | + budget (float): The amount of money you own. |
| 37 | + exchanging_value (float): The amount of your money you want to exchange now. |
| 38 | +
|
| 39 | + Returns: |
| 40 | + float: The amount left of your starting currency after the exchange |
| 41 | +
|
| 42 | + Examples: |
| 43 | + .>>> get_change(127.5, 120.0) |
| 44 | + 7.5 |
| 45 | +
|
| 46 | + >>> get_change(300.75, 150.25) |
| 47 | + 150.50 |
| 48 | +
|
| 49 | + This function calcultes and returns the amount of money left over from the budget |
| 50 | + after an exchange. |
21 | 51 |
|
22 | | - :param budget: float - amount of money you own. |
23 | | - :param exchanging_value: float - amount of your money you want to exchange now. |
24 | | - :return: float - amount left of your starting currency after exchanging. |
25 | 52 | """ |
26 | 53 |
|
27 | 54 | return budget - exchanging_value |
28 | 55 |
|
29 | 56 |
|
30 | 57 | def get_value_of_bills(denomination, number_of_bills): |
31 | | - """ |
| 58 | + """Calculate the total value of currency at current denomination. |
| 59 | +
|
| 60 | + Parameters: |
| 61 | + denomination (int): The value of a single unit (bill). |
| 62 | + number_of_bills (int): The total number of units (bills). |
| 63 | +
|
| 64 | + Returns: |
| 65 | + int: Calculated value of the units (bills). |
| 66 | +
|
| 67 | + Examples: |
| 68 | + >>> get_value_of_bills(5, 128) |
| 69 | + 640 |
| 70 | +
|
| 71 | + >>> get_value_of_bills(15.13, 16) |
| 72 | + 242 |
| 73 | +
|
| 74 | + This function calculates and returns the total value of the bills (excluding fractionaal amounts). |
32 | 75 |
|
33 | | - :param denomination: int - the value of a bill. |
34 | | - :param number_of_bills: int - total number of bills. |
35 | | - :return: int - calculated value of the bills. |
36 | 76 | """ |
37 | 77 |
|
38 | 78 | return denomination * number_of_bills |
39 | 79 |
|
40 | 80 |
|
41 | 81 | def get_number_of_bills(amount, denomination): |
42 | | - """ |
| 82 | + """Calculate the number of currency units (bills) within the amount. |
| 83 | +
|
| 84 | + Parameters: |
| 85 | + amount (float): The total starting value. |
| 86 | + denomination (int): The value of a single unit (bill). |
| 87 | +
|
| 88 | + Returns: |
| 89 | + int: The number of units (bills) that can be obtained from the amount. |
| 90 | +
|
| 91 | + Examples: |
| 92 | + >>> get_number_of_bills(127.5, 5) |
| 93 | + 25 |
| 94 | +
|
| 95 | + >>> get_number_of_bills(35.16, 10) |
| 96 | + 3 |
| 97 | +
|
| 98 | + This function calcluates and returns the number pf currency units (bills) that can |
| 99 | + be obtained from the given amount. Whole bills only - no fractioal amounts. |
43 | 100 |
|
44 | | - :param amount: float - the total starting value. |
45 | | - :param denomination: int - the value of a single bill. |
46 | | - :return: int - number of bills that can be obtained from the amount. |
47 | 101 | """ |
48 | 102 |
|
49 | 103 | return int(amount) // denomination |
50 | 104 |
|
51 | 105 |
|
52 | 106 | def get_leftover_of_bills(amount, denomination): |
53 | | - """ |
| 107 | + """Calculate leftover amount after exchanging into bills. |
| 108 | +
|
| 109 | + Parameters: |
| 110 | + amount (float): The total starting value. |
| 111 | + denomination (int): The value of a single unit (bill). |
| 112 | +
|
| 113 | + Returns: |
| 114 | + float: The amount that is "leftover", given the current denomination. |
| 115 | +
|
| 116 | + Examples: |
| 117 | + >>> get_leftover_of_bills(127.5, 20) |
| 118 | + 7.5 |
| 119 | +
|
| 120 | + >>> get_leftover_of_bills(153.2, 10) |
| 121 | + 3.20 |
| 122 | +
|
| 123 | + This function calculates and returns the leftover amount that cannot be |
| 124 | + returned from starting amount, due to the currency denomination. |
54 | 125 |
|
55 | | - :param amount: float - the total starting value. |
56 | | - :param denomination: int - the value of a single bill. |
57 | | - :return: float - the amount that is "leftover", given the current denomination. |
58 | 126 | """ |
59 | 127 |
|
60 | 128 | return amount % denomination |
61 | 129 |
|
62 | 130 |
|
63 | 131 | def exchangeable_value(budget, exchange_rate, spread, denomination): |
64 | | - """ |
| 132 | + """Calculate the maximum value of the new currency. |
| 133 | +
|
| 134 | + Parameters: |
| 135 | + budget (float): The amount of your money you are planning to exchange. |
| 136 | + exchange_rate (float): The unit value of the foreign currency. |
| 137 | + spread (int): The percentage that is taken as an exchange fee. |
| 138 | + denomination (int) The value of a single unit (bill). |
| 139 | +
|
| 140 | + Returns: |
| 141 | + int: The maximum value you can get in the new currency. |
65 | 142 |
|
66 | | - :param budget: float - the amount of your money you are planning to exchange. |
67 | | - :param exchange_rate: float - the unit value of the foreign currency. |
68 | | - :param spread: int - percentage that is taken as an exchange fee. |
69 | | - :param denomination: int - the value of a single bill. |
70 | | - :return: int - maximum value you can get. |
| 143 | + Examples: |
| 144 | + >>> exchangeable_value(127.25, 1.20, 10, 20) |
| 145 | + 80 |
| 146 | +
|
| 147 | + >>> exchangeable_value(127.25, 1.20, 10, 5) |
| 148 | + 95 |
| 149 | +
|
| 150 | + Note: |
| 151 | + The currency denomination is a whole number and cannot be sub-divided. |
| 152 | +
|
| 153 | + This function calculates and returns the maximum value of the new currency after |
| 154 | + determining the exchange rate plus the spread. |
71 | 155 | """ |
72 | 156 |
|
73 | 157 | exchange_fee = (exchange_rate / 100) * spread |
74 | 158 | exchange_value = exchange_money(budget, exchange_rate + exchange_fee) |
75 | 159 | number_of_bills = get_number_of_bills(exchange_value, denomination) |
76 | 160 | value_of_bills = get_value_of_bills(denomination, number_of_bills) |
| 161 | + |
77 | 162 | return value_of_bills |
0 commit comments