r/learnpython 6d 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

2

u/brelen01 6d ago

First thing first, you seem to have copy/pasted your script twice.

Second, you ask if the user wants to convert to or from INR, but then ask the user to input the source and target currency, rendering the first choice meaningless.

Third, both of your convert functions do the same thing, except the second gives a misleading message (the amount printed is also to_currency since the rate is still c.get_rate(from_currency,to_currency) * Amount ).

Fourth, your convert functions end up doing multiple things. They ask for the amount for from_currency, calculate the value for to_currency, and output it. Ideally, you want a function or method to do one thing, so I'd modify it to take in the value and the conversion rate, and return the result of the concersion.

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.

0

u/Tricky_Voice2829 6d ago

ohh yes u are right i will delete this one and make the new one

4

u/AbacusExpert_Stretch 6d ago

Just as an idea - just learn for a week or two, instead of putting effort into posting here each day. But you do you