A web page that contains a form
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Challenge</title>
</head>
<body>
<p>
Halt! Who goes there?
</p>
<form action="response.py" method="get">
<input type="text" name="firstname" />
<input type="text" name="surname" />
<input type="submit" />
</form>
</body>
</html>
The server-side program, response.py
#!/usr/local/bin/python3
from cgi import FieldStorage
print('Content-Type: text/html')
print()
form_data = FieldStorage()
fname = form_data.getfirst('firstname')
sname = form_data.getfirst('surname')
print("""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Response</title>
</head>
<body>
<p>
Hello, %s %s. You may go on your way.
</p>
</body>
</html>""" % (fname, sname))
Incomplete solution
#!/usr/local/bin/python3
from cgi import FieldStorage
print('Content-Type: text/html')
print()
print("""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Your message in Morse code</title>
</head>
<body>
<table>
<tr>
<th>Original: </th><td>%s</td>
</tr>
<tr>
<th>Morse: </th><td>%s</td>
</tr>
</table>
</body>
</html>""" % (message, morse))
Complete solution
#!/usr/local/bin/python3
from cgi import FieldStorage
print('Content-Type: text/html')
print()
morse_dict = {
'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.',
'F': '..-.', 'G': '--.', 'H': '....', 'I': '..', 'J': '.---',
'K': '-.-', 'L': '.-..', 'M': '--', 'N': '-.', 'O': '---',
'P': '.--.', 'Q': '--.-', 'R': '.-.', 'S': '...', 'T': '-',
'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-', 'Y': '-.--',
'Z': '--..'
}
form_data = FieldStorage()
message = form_data.getfirst('message')
morse_list = [morse_dict[char.upper()] for char in message]
morse = ' '.join(morse_list)
print("""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Your message in Morse code</title>
</head>
<body>
<table>
<tr>
<th>Original: </th><td>%s</td>
</tr>
<tr>
<th>Morse: </th><td>%s</td>
</tr>
</table>
</body>
</html>""" % (message, morse))