CGI Practice 1 (5 blanks)
import cgi
import html
form = cgi.__________(1)
name = form.__________(2)("name", "Guest")
safe_name = html.__________(3)(name)
print("Content-Type: ________(4)")
print()
print("<h1>Hello</h1>")
print("Name =", ________(5))
Answers
(1) FieldStorage()
(2) getfirst
(3) escape
(4) text/html
(5) safe_name
CGI Practice 2 (5 blanks)
#! /usr/bin/env python
import cgi
form = cgi.__________(1)
email = form.__________(2)("email", "")
print("Content-Type: ________(3)")
print()
if email == "":
print("________(4)")
else:
print("Email =", ________(5))
Answers
(1) FieldStorage()
(2) getfirst
(3) text/plain
(4) No email submitted
(5) email
CGI Practice 3 (5 blanks)
import cgi
import html
form = cgi.__________(1)
comment = form.__________(2)("comment", "")
comment = html.__________(3)(comment)
print("Content-Type: ________(4)")
print()
print("Comment =", ________(5))
Answers
(1) FieldStorage()
(2) getfirst
(3) escape
(4) text/html
(5) comment
SQL Practice 1 (5 blanks)
import [Link]
con = [Link].__________(1)(
host="localhost", user="root", password="password", database="school")
cur = con.__________(2)
cur.__________(3)("SELECT * FROM course")
rows = cur.__________(4)()
for row in ________(5):
print(row)
Answers
(1) connect
(2) cursor()
(3) execute
(4) fetchall
(5) rows
SQL Practice 2 (5 blanks)
import [Link]
db = [Link].__________(1)(host="localhost", user="root",
password="password", database="shop")
cur = db.__________(2)
sql = "INSERT INTO products(name, price) VALUES (%s, %s)"
val = ("Pen", 500)
cur.__________(3)(sql, val)
db.__________(4)()
cur.__________(5)()
Answers
(1) connect
(2) cursor()
(3) execute
(4) commit
(5) close
SQL Practice 3 (5 blanks)
import [Link]
db = [Link](host="localhost", user="root",
password="password", database="shop")
cur = db.__________(1)
cur.__________(2)("SELECT * FROM products WHERE price > %s", (300,))
for row in cur.__________(3)():
print(__________(4))
db.__________(5)()
Answers
(1) cursor()
(2) execute
(3) fetchall
(4) row
(5) close