CS 1MD3 - Winter 2006 - Assignment #5
Generated for Student ID: 0462082
Due Date: April 5th, 2006
(You are responsible for verifying that your student number is
correct!)
NOTE: All submissions must be plain text format in ".py"
files.Instructions
Using the libraries sys and urllib
, write a Python program to convert the value of a given amount of money from one currency to another. Your program will prompt the user for two 3-letter currency codes (the "from" currency, and the "to" currency) along with a floating-point value. It will acquire the conversion from www.oanda.com, extract the relevant text, and display it in the console. Here are some results which your program should reproduce (with current monetary values, of course):
$ python currency.py
Convert from: CAD
Convert to: USD
Amount: 23.59
23.59 Canadian Dollar = 20.41788 US Dollar
$ python currency.py
Convert from: EUR
Convert to: JPY
Amount: 84.24
84.24 Euro = 11,947.6 Japanese Yen
$ python currency_cmdline.py
Convert from: ISK
Convert to: GTQ
Amount: 123.45
123.45 Iceland Krona = 13.66300 Guatemalan Quetzal
The URL: http://www.oanda.com/convert/classic
Notes:
- You may assume that the user has given valid input. No need to check that valid currency codes have been entered, or that a floating-point number has been given. Just assume the user knows what he or she is doing.
- You must mimic the output format exactly as shown above. This will mean discarding huge amounts of HTML to get at the relevant text.
- Although the web form at www.oanda.com contains several variables (
language, margin, lang,
etc.), it appears to require only an amount and the two currency codes. Use the variables value
, exch2
, and expr2
for this purpose.