Help With Currency Exchange Task 6

Hi

I do not understand what I am supposed to to do on Task 6. What am I supposed to do after calculating the actual exchange rate? What am I supposed to do with the budget and denomination variables? The hint says to do something with division, but I don’t know what to divide. I don’t understand it at all. Please help.


def exchange_money(budget, exchange_rate):
    """

    :param budget: float - amount of money you are planning to exchange.
    :param exchange_rate: float - unit value of the foreign currency.
    :return: float - exchanged value of the foreign currency you can receive.
    """
    exchange_rate = budget / exchange_rate
    return exchange_rate


def get_change(budget, exchanging_value):
    """

    :param budget: float - amount of money you own.
    :param exchanging_value: float - amount of your money you want to exchange now.
    :return: float - amount left of your starting currency after exchanging.
    """

    change = budget - exchanging_value
    return change


def get_value_of_bills(denomination, number_of_bills):
    """

    :param denomination: int - the value of a bill.
    :param number_of_bills: int - total number of bills.
    :return: int - calculated value of the bills.
    """

    value = denomination * number_of_bills
    return value 

def get_number_of_bills(amount, denomination):
    """

    :param amount: float - the total starting value.
    :param denomination: int - the value of a single bill.
    :return: int - number of bills that can be obtained from the amount.
    """

    number_of_bills = amount // denomination
    return number_of_bills

def get_leftover_of_bills(amount, denomination):
    """

    :param amount: float - the total starting value.
    :param denomination: int - the value of a single bill.
    :return: float - the amount that is "leftover", given the current denomination.
    """

    leftover_of_bills = amount % denomination
    return leftover_of_bills
def exchangeable_value(budget, exchange_rate, spread, denomination):
    """

    :param budget: float - the amount of your money you are planning to exchange.
    :param exchange_rate: float - the unit value of the foreign currency.
    :param spread: int - percentage that is taken as an exchange fee.
    :param denomination: int - the value of a single bill.
    :return: int - maximum value you can get.
    """
    exchange_rate = budget / exchange_rate 
    spread = exchange_rate * spread / 100 
    actual_rate = exchange_rate + spread

Hello Rdin2,

here’s my solution. Try this:

4 Likes

Thank you! Your solution worked! I would like to know how you figured it out.

The (exchange_rate + (exchange_rate * (spread / 100 ))) part seems to be equivalent to the actual_value variable I created in my own code. I tried recreating your problem using my variables but I got an error:

   exchange_rate = budget / exchange_rate 
   spread = exchange_rate * spread / 100 
   actual_rate = exchange_rate + spread
   val_after_exchange = budget / actual_rate // denomination
   return val_after_exchange

What did the parenthesis, budget , and the denomination variables do in your solution?

Note how the prior solution uses denomination twice while yours mentions it once.

1 Like

Thank you! I got my final iteration:

    spread = exchange_rate * spread / 100 
    actual_rate = exchange_rate + spread
    val_after_exchange = budget / actual_rate // denomination
    return val_after_exchange * denomination
1 Like

damn i had the exact same problem.

i dont get what is denomination, what it does. after seeing ur code i made it, but i still dont get it.

i dont know why we divide it first, and then why we multiply after.

Maybe it could say something about it on task 6. because the spread part i was burning my mind to solve this percent stuff fee over the amount that is the rate in which the money would be exchanged. damn it burned my mind.

but even solving that part, i had no clue what to do with this denomination stuff. so i just had to google or whatever. not even chatgpt knew what to do. he said denomination is a value in which the final value gets multiplied. He tried. But i was clueless even so.

in the end i did it, but im kinda sad that i coudnt do it on my own.

anyway. thank you

1 Like

The denomination is the size of the final bill. If you’re supposed to get back $105 but they only have $50 bills, you’ll get two $50 bills, or, $100.

105 // 50 == 2 and 2 * 50 == 100

1 Like

Hi,

I was in holiday mood and didn’t login to exercism for a few days. Sorry, that I didn’t answer your message. But it looks like you figured it out with IsaacG anyway. You use denomination in the first place to make a floor division and get a number which fits to the bill size they can exchange. In the next step you have to multiply it to know, how much money you get out. I think that was the solution.

Have a good new year!

1 Like