This Python program contains a simple program for converting currency in real-time using the Forex Python Library. The Forex-Python library provides the most direct way to get a currency conversion rate through API calls. It has different functions, which take the currency codes you want to convert from one currency to another and then return the current value.
In this Python program, we are converting USD to INR. It will ask you to input the amount and the currency codes you want to convert.
An example of currency conversion using forex_ python:
from forex_python.converter import CurrencyRates cr = CurrencyRates() amount = int(input("Please enter the amount you want to convert: ")) from_currency = input("Please enter the currency code that has to be converted: ").upper() to_currency = input("Please enter the currency code to convert: ").upper() print("You are converting", amount, from_currency, "to", to_currency,".") output = cr.convert(from_currency, to_currency, amount) print("The converted rate is:", output)
Please enter the currency code that has to be converted: USD
Please enter the currency code to convert: INR
You are converting 1 USD to INR.
The converted rate is: 77.58766511451107
The forex-python library can be installed using pip (package manager for Python). The following command installs the package:
pip install forex-python