import cgi, sys
params = cgi.FieldStorage()
if "rows" in params:
rows = int(params["rows"].value)
else:
rows = -1
print "Content-type: text/html"
print
print """<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Треугольник Паскаля</title>
</head>
<body>"""
if rows < 0:
print "<div style='color: red;'>Не задан параметр запроса rows.</div>"
print """</body>
</html>"""
sys.exit(1)
print "<table>"
for n in range(0, rows):
print "<tr>"
print "<td>{}:</td>".format(n)
for i in range(1, (rows - n) / 2):
print "<td></td>"
Cnk = 1
print "<td>{}</td>".format(Cnk)
for k in range(1, n + 1):
Cnk = Cnk * (n - k + 1) / k
print "<td>{}</td>".format(Cnk)
print "</tr>"
print "</table>"
print """</body>
</html>"""