# Script that inputs currency code, then outputs exchange rate. from urllib.request import urlopen from json import loads # Define URL for reading exchange rates in JSON format. url = "http://facweb.cdm.depaul.edu/sjost/it212/rates.json.txt" # Open input stream input_stream = urlopen(url) # Read raw bytes from input stream rawbytes = input_stream.readline( ) print(rawchars) input_stream.close( ) # Decode json_string = rawchars.decode("utf-8-sig").strip( ) # Load dictionary from JSON string exchange_rates = loads(json_string) # Input currency code currency_code = input("Enter currency code: ") # Look up exchange rate in dictionary if currency_code in exchange_rates: print("Exchange rate: ", exchange_rates[currency_code]) else: print("Currency code not in dictionary.")