In this tutorial I will show you how to create a currency convertor using python program.
Install required Package:
pip install python-dateutil requests BeautifulSoup4
PYTHON CODE:
import requests from bs4 import BeautifulSoup as bs import re from dateutil.parser import parse def convert_currency_xe(src, dst, amount): url = f"https://www.xe.com/currencyconverter/convert/?Amount={amount}&From={src}&To={dst}" content = requests.get(url).content soup = bs(content, "html.parser") exchange_rate_html = soup.find_all("p")[2] last_updated_datetime = parse(re.search(r"Last updated (.+)", exchange_rate_html.parent.parent.find_all("div")[-2].text).group()[12:]) return last_updated_datetime, exchange_rate_html.text if __name__ == "__main__": from_currency = input("From Currency: ").upper() to_currency = input("To Currency: ").upper() amount = int(input("Enter the amount: ")) last_updated_datetime, exchange_rate = convert_currency_xe(from_currency, to_currency, amount) print("Last updated datetime:", last_updated_datetime) print(f"{amount} {from_currency} = {exchange_rate} {to_currency}")
OUTPUT:

VIDEO GUIDE:
Post your comments / questions
Recent Article
- Fix-Gradient effect turning to gray in after effects
- How to blur an image in python?
- ModuleNotFoundError: No module named 'whois' in Python GoviralHost Without Terminal
- How to Convert Image to Pencil Sketch in Python?
- AttributeError: module 'urllib' has no attribute 'request' - Python
- How to Extract audio from video files using python?
- PermissionError: [Errno 13] Permission denied: 'shampoo_sales.csv' - Python
- [WinError 145] The directory is not empty: 'FolderPath' - Python
Related Article