#Currency Exchange Task 6 [Exercism Pythons Exercises]

29 messages · Page 1 of 1 (latest)

blissful raven
#

I'm having some issues on how to type the proper answer. I believe I'm in the ball-park, but for some reason, I just cannot come up with the expected answer.

    exchange_fee = (spread / 100) * exchange_rate
    foreign_currency = exchange_rate + exchange_fee
    exchanged_money = budget / foreign_currency
    return int(exchanged_money / denomination)
AssertionError: 35 != 1400 : Called exchangeable_value(1500, 0.84, 25, 40). The function returned 35, but The tests expected 1400 as the maximum value of the new currency .
cold ether
#

You should read the instruction again and understand what it wants at the end, and then look at your code and see what it actually gives.

#

You need to understand both parts to properly solve this.

blissful raven
#

I've read it multiple times, and felt in logical English that I was making the right things, but I suppose I'm just not understanding it.

hasty sigil
#

Can you explain, in English, what the last line does (conceptually -- the intent, not the actual code)

blissful raven
#

I would imagine it should divide the above line(exchanged code) by the value of each bill to make the max amount of bills to be aquired, then giving the max value of money to be withdrawn.

hasty sigil
#

There is a "then" in the English, which implies two steps. The code only has one step.

#

the max amount of bills to be aquired
I see this in the code.
then giving the max value of money to be withdrawn.
I don't see this in the code.

blissful raven
#

im sorry, i don't quite see where that then would go, as I typed the last statement, I imagined, I should have another result and give a name to the previous return minstead of that being the finisher.

#

I think I see what you're talking about.

#

I was wrong. I don't see it

#
exchange_fee = (spread / 100) * exchange_rate
    foreign_currency = exchange_rate + exchange_fee
    exchanged_money = budget / foreign_currency
    amount_of_bills = int(exchanged_money / denomination)
    return int(amount_of_bills * foreign_currency)
#
AssertionError: 99997 != 8568 : Called exchangeable_value(100000, 10.61, 10, 1). The function returned 99997, but The tests expected 8568 as the maximum value of the new currency .
hasty sigil
#

It looks like you made some progress 😉

#

Could you explain that last line of code in English? What is the intent of that code? What does it actually do?

blissful raven
#

it should be the amount of bills as calculated above, multiplied by the dividend of the exchanged money.

hasty sigil
#

Assume for a moment we're converting $100 to $100 with a lucky exchange rate of exactly 1.00.
If there are 20 bills, what would you expect the return value to be? What would you get if you compute "the amount of bills as calculated above, multiplied by the dividend of the exchanged money"?

blissful raven
#

with that logic I would expect to get $100 back.

hasty sigil
#

20 bills x $100 would be ... $2000?

blissful raven
#

oh nevermind. I jumped the gun on my answer

hasty sigil
#

😉 Checking your logic with simple inputs can be handy

blissful raven
#

I feel like it's just a lot of things in one sequence, and I'm having issues wrapping my head around it.

hasty sigil
#

Yup! It is. There's a lot of steps here. This is where planning and working out the logic before writing code is handy.

blissful raven
#

I think I've been learning for a total of about 3 hours now at a computer haha. Almost feeling rushed.

#

right. To even get where I got this time, I had to go minto notepad and jot down notes beforehand.

hasty sigil
#
  1. Understand the task.
  2. Figure out what steps need to be taken -- in English or something close to it.
  3. Maybe double check your logic with some examples.
  4. Turn steps into code.
#

Anyhow. Assume the currently exchange rate ends up being 1.01 and you're converting $100 USD to $101 CAD but you're using $5 bills. So your exchanged value is $101 and you get back 20 bills. You got all the code for all of that, IIUC. You're just missing the last step.

blissful raven
#

I think I got the solution.

#
exchange_fee = (spread / 100) * exchange_rate
    foreign_currency = exchange_rate + exchange_fee
    exchanged_money = budget / foreign_currency
    amount_of_bills = int(exchanged_money // denomination)
    return amount_of_bills * denomination