Skip to content

Practical exercise

Fetch live PKR USD exchange rate from a free API

An API is a polite way for one program to ask another program for fresh data. The internet is mostly pipes carrying these tiny questions and answers. Today you will write five lines of Python that ask a public free API for today's PKR USD rate, and print it. The same shape of code powers banking apps, ride hailing, and food delivery.

40 min·practitioner
Mimi the mascot, encouraging you

Now try it

Fetch live PKR USD exchange rate from a free API

Stretch

Wrap the code in a function get_rate(currency) that returns the rate for any 3 letter code. Loop over PKR, INR, AED, GBP, SAR, USD and print all six. Save Repl URL.

Goes into your portfolio

A screenshot showing live PKR rate fetched from a public API plus a 100 USD to PKR calculation, and a relative's WhatsApp reply confirming or contesting the rate.