Date:

Share:

Currency converter using Python

Related Articles

Hi, Web Programmer Today we manufacture a currency converter using Python. As we know Python is a very diverse programming language and is used by the big technology giants. Anyway, we use API facility To get the conversion rates in real time and convert the appropriate amount. So, get your API key from Here.

installation

we need requests Module to call this API.

Type the following command to install it,

pip install requests

Code

import requests
api_url_end = 'http://data.fixer.io/api/latest?access_key=YOUR_API_KEY_HERE'

def currency_convertor(currency_from,currency_to,amount):
    rate = response.json()['rates'][currency_from]
    amount_in_EUR = amount/rate
    result = amount_in_EUR*(response.json()['rates'][currency_to])
    print(result)

response=requests.get(api_url_end)

print('List of country code '+str(response.json()['rates'].keys())+'n')

convert_from = input('Currency from: ')
convert_to = input('Currency to: ')

amount_to_convert = int(input("Enter the amount to convert: "))

currency_convertor(base_currency,convert_to,amount_to_convert)

# follow on instagram @code_snail

Productivity

First, import the requests module and then we will announce api_url_end That they have a currency API endpoint and you need to replace the YOUR_API_KEY_HERE you will receive after registering at fixer.io

Before understanding currency_convertor Function, we call the endpoint of our API using requests.get() We then print the country code that the user can easily find.

We then ask the user from which currency to which currency he wants to convert and then we will ask the amount to convert it and store it convert_from, convert_to and amount_to_convert Respectively

After we called currency_convertor() Function with convert_from, convert_to and amount_to_convert Arguments.

We define a function currency_convertor Which takes 3 input arguments i.e. currency_from, currency_to, amount.

Then we will define rate As a variable that stores the base currency exchange rate. Then think amount_in_EUR Since the base currency of the data obtained is the Euro.
And finally, the result will be amount_in_EUR Multiplied by the rate of currency_to.

Must try this mini-project and share it with your friends. follow me on Instagram @code_snail

Also try,

  • Text for ASCII art using python
  • Convert any image to ASCII art in Python
  • Perform a handwritten task using Python

Source

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Popular Articles