Question: Assignment Overview This assignment will give you more experience on the use of strings and iterations. The goal of this project is to use Googles
Assignment Overview
This assignment will give you more experience on the use of strings and iterations. The goal of this project is to use Googles currency converter API to convert currencies in Python and display the result to user by processing the returned results.
Assignment Background
The acronym API stands for Application Programming Interface. It is usually a series of functions, methods or classes that supports the interaction of the programmer (the application developer, i.e., you) with some particular program. Google has several API's available for anyone to use. To interact with Googles currency converter API, you have to create a GET request which is basically a URL and some values inserted in specific places. Our goal is to prompt the user for an amount, original currency and target currency, then setup the URL and request Google currency converter to convert it. We then process the returned value to extract the result, then display it to the user.
Project Description
Your program must meet the following specifications: 1. At program start, prompt the user for the original currency. 2. Then prompt the user for the target currency. 3. Next prompt for the amount which must be an int. 4. Setup the URL as explained below and send the request. 5. Convert the returned value to string, and then process it to find the converted value. 6. Display the result to the user. 7. Prompt the user if they want to repeat.
Set up URL
A sample URL is https://finance.google.com/finance/converter?a=100&from=USD&to=EUR You can put that link in a browser and see how Google currency converter converts 100 USD to EUR (convert $100 US to Euros). To change the amount or the currencies, you can simply replace those values in the URL by the values entered by the user. For this project, you can assume the users currency input is always correct. You will need to check that the amount to be converted is correct. The URL needs to be a string for use in the urlopen(url) call below. You need to construct a URL string that has a value (such as 100 in sample URL above), the currency you are converting from (such as USD in the sample URL above) and the currency you are converting to (such as EUR in the sample URL above). You will be prompting for those three values so you need to insert them into your URL string. How do you do that? In Python we have the string format statement described in Section 4.4 of the text. Usually it is use inside a print()function, but it doesnt have to be. Consider this code:
some_str = 'XYZ'
some_int = 123
a_str = "abc{:d}def{:s}".format(some_int,some_str)
print(a_str) # prints abc123defXYZ
Process Results
Your project should start by importing urllib.request. You can use response = urllib.request.urlopen(url) to do the conversion. Then read the response and convert it to string by result = str(response.read()). To find the converted value in the result string, you can find that appears right before the value we are looking for and that appears right after that (Hint: we said find as a hint to use the string find() method on the result string). You can then extract the value by slicing the result string using the indices you found.
Input Value Checking
The value input must be an integer. In a non-integer is input, you must re-prompt for the value (not reprompt for the currency names). Hint: use a while loop (because you dont know how many times an incorrect value will be input, and the string isdigit() method is useful to checking if an input string is all digits, i.e. is an integer.
Output Value
The value output must be a decimal with two decimal places
import urllib.request # Strings: #"What is the original currency? " #"What currency do you want to convert to? " #"How much do you want to convert (int)? " #"The value you input must be an integer. Please try again." #"Do you want to convert another currency? "
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
