I am making a currency converter. How do I get python to accept both integer and float?
This is how I did it:
def aud_brl(amount,From,to):
ER = 0.421
Use the isinstance function, which is built in
if isinstance(num, (int, float)):
#do stuff
Also, you should refrain from using reserved keywords for variable names. The keyword from is a reserved keyword in Python
Finally, there is one other error I noticed:
if From == 'aud' or 'brl'
Should be
if From == 'aud' or From == 'brl'
Lastly, to clean up the if statements you could theoretically use the list (if you have more currencies in the future, this might be better.
currencies = ['aud', 'brl'] #other currencies possible
if From in currencies and to in currencies:
#do conversion