Skip to content

Latest commit

 

History

History
22 lines (18 loc) · 1.17 KB

README.md

File metadata and controls

22 lines (18 loc) · 1.17 KB

Currency Converter

This repository is about currency converter that was built usning Jaclang

The code starts by importing necessary modules:

urllib.request: This module provides functions for working with URLs and making HTTP requests.
json: This module is used for working with JSON data.

with entry{} is acts likes a main function It takes and validates the input (ensuring the amount is numeric and greater than 0).
Finally, it calls the convert_currency function with the provided input and prints the result.

The convert_currency function takes three parameters:

init_currency: The initial currency code (e.g., “USD” for US Dollar).
target_currency: The target currency code (e.g., “EUR” for Euro).
amount: The amount to be converted.

Inside the function:

An API key (you need to replace it with your own) is defined.
A URL is constructed using the provided parameters.
An HTTP request is made to the API using urllib.request.urlopen.
The response is read and decoded as JSON.
If the response contains a “result” field, it returns the conversion result; otherwise, it returns an error message.