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
- The request was aborted: Could not create SSL/TLS secure channel -Error in Asp.net
- FieldError: Cannot resolve keyword 'id' into field in Django project
- How to hide the ID field from the Django admin?
- It is impossible to add a non nullable field without specifying a default. Django error
- ImportError: cannot import name 'url' from 'django.conf.urls' - Django Error
- How to Enable Virtualization in BIOS Security Settings in Intel Processors For Android Studio?
- Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it.
- AttributeError: 'NoneType' object has no attribute 'get_text' - Python
Related Article