<meta name="clckd" content="6301244fb7ed470eb1cd6b8c31d01ac4" />
Python

Python | Finding The Current Exchange Rate Between Any Two Currencies

Python Script | Finding the current exchange rate between any two currencies using Python.

Normally we look at the currencies exchange rate between two currencies on the browser but we can find the current exchange rate between two currencies using python script. 

Finding the current exchange rate between any two currencies using Python

Here is the Script below

  


import json
import sys
import urllib.request

if len(sys.argv) != 3:
    print("Usage: ./currencyrates.py lookup_currency base_currency. Example: ./currencyrates.py cad usd")
    sys.exit()

currency = sys.argv[1]
basecurrency = sys.argv[2]

currencyurl = "http://freecurrencyrates.com/api/action.php?do=cvals&iso=" + currency + "&f=" + basecurrency + "&v=1&s=cbr"
f = urllib.request.urlopen(currencyurl)
obj = json.loads(f.read())
result = "1 " + currency.upper() + " is "
result+="{:,.2f}".format(1/obj[currency.upper()]) + " " + basecurrency.upper()

print(result);


Run



python cur.py inr usd

Thank You
Shivam Rohilla | Python Developer

 

 

0 Comments
  • No Reviews Yet

Leave a Reply
Please Sign In For Comment.
Login or Signup
Shivam Rohilla
Hi, I'm Shivam Rohilla

Hi! My name is Shivam Rohilla. I am a Full Stack Web Developer, and I'm very passionate and dedicated to my work. With 2 years experience as a professional Full Stack Web Developer.

Follow Me:-

My social media links