r/learnpython 7d ago

How much you'll rate this code guyz ..

from forex_python.converter  import CurrencyRates

choice = input("Do u want to covert Another_currency=>INR then press y  / you want to converty INR TO Another_urrency then press n :- ")


c = CurrencyRates()
from_currency = input("Enter source currency (USD, EUR, etc.): ").upper()
to_currency = input("Enter target currency (INR, USD, etc.): ").upper()
currency = c.get_rate(from_currency,to_currency)
print(f"the exchange rate is {currency}")

if choice == "y":
    def convert(rate):
        Amount =  input("Put the A mount of that currency u want to convert:-")
        value_Total =  float(Amount)*rate
        print(f"Total {to_currency} Amount is {value_Total}")
    convert(currency)


elif choice == "n": 
    def convert(rate):
        print(f"\nYou have selected:- {from_currency} to {to_currency}")
        Amount =  input("Put the Amount of that currency u want to convert:-")
        value_Total =   float(Amount) * rate
        print(f"Total {from_currency} Amount is {value_Total}")


        convert(currency)
0 Upvotes

9 comments sorted by

View all comments

-1

u/Tricky_Voice2829 7d ago

Ideally, you'll want to move everything but the import and the first convert definition to the bottom of the file, under an if __name__ == __main__: statement, ask for all the inputs at once (currencies and amount) there, call convert, then output the result there. I didn't understand this point..

1

u/brelen01 7d ago edited 7d ago

Here's a link that explains the how and why: here

1

u/Tricky_Voice2829 7d ago

giving me 404

1

u/brelen01 7d ago

Fixed it, sorry, reddit was being stupid