Currency Converter in Python

Python is a very versatile programming language. Python is being used in almost each mainstream technology and one can develop literally any application with it. Let’s see a Python program to convert the currency of one country to that of another country. To use this service, one must need the API key, which can be get form here.
We will use fixer API to get the live conversion rates and convert the corresponding amount.

Modules needed:

requests: This module does not built-in with python. To install it type the below command in the terminal or cmd.

pip install requests

Below is the implementation:





# Python program to convert the currency
# of one country to that of another country 
# Import the modules needed
import requests
class Currency_convertor:
    # empty dict to store the conversion rates
    rates = {} 
    def __init__(self, url):
        data = requests.get(url).json()
        # Extracting only the rates from the json data
        self.rates = data["rates"
    # function to do a simple cross multiplication between 
    # the amount and the conversion rates
    def convert(self, from_currency, to_currency, amount):
        initial_amount = amount
        if from_currency != 'EUR' :
            amount = amount / self.rates[from_currency]
        # limiting the precision to 2 decimal places
        amount = round(amount * self.rates[to_currency], 2)
        print('{} {} = {} {}'.format(initial_amount, from_currency, amount, to_currency))
# Driver code
if __name__ == "__main__":
    url = str.__add__('', YOUR_ACCESS_KEY)  
    c = Currency_convertor(url)
    from_country = input("From Country: ")
    to_country = input("TO Country: ")
    amount = int(input("Amount: "))
    c.convert(from_country, to_country, amount)


Input :

From Country: USD 
TO Country: INR 
Amount: 1 

Output :

1 USD = 70.69 INR

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.