From USD
Lesson 4 of 5 in Coddy's Currency Converter - Python Project course.
Now let's create the other helper function - from_usd.
Challenge
MediumCreate another function named from_usd that gets currency to convert to and amount of USD.
The function will return its equivalent value in the currency from the input, round the result to 4 floating digits..
Handle the same errors from to_usd.
Don't delete
to_usdfunction, we will need it for later!
Try it yourself
CURRENCIES = {
'USD': 1,
'EUR': 1.06,
'YEN': 0.0067,
'GBP': 1.23,
'AUD': 0.64,
'CAD': 0.74
}
def to_usd(from_currency, amount):
if from_currency not in CURRENCIES:
raise Exception(f'{from_currency} is not supported')
elif amount < 0:
raise Exception(f'Invalid amount')
else:
res = CURRENCIES[from_currency] * amount
return res