- The import statements on top of your script should be
from urllib.request import urlopen
import json
import sqlite3
import sys
- Use input statements to input these items:
name (str) date (str) source_currency (str)
target_currency (str) source_amount (float)
- You must use the dictionary twice, once to obtain the source currency
srand the second time to obtain the target currency
tc. Use sys.exit to
directly exit your script if an illegal currency code is entered at the keyboard:
if sc in d:
sr = d[sc]
else:
print("Code for source currency not found.")
sys.exit( )
if tc in d
tr = d[tc]
else:
print("Code for target currency not found.")
sys.exit( )
- Use this statement to create the output database:
conn = sqlite3.connect('lab3transactions.db')
- Modify the kids table to create a table named transactions with these columns:
Column | Datatype |
name | varchar(15) |
source_currency | varchar(3) |
target_currency | varchar(3) |
source_amount | float |
source_exchange_rate | float |
target_exchange_rate | float |
target_amount | float |
- When you modify the insert statement
# Insert values into database.
cur.execute(f'''insert into kids values(
'{name}', '{gender}', {age});''')
remember that in SQL, string values need single quotes, but numeric values (int and
float)
do not use single quotes.