(just posted this same code, but I'm confused on a different part.) When this code prints I receive this error:
TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'
I need a quote or image to print in place of '%s' but can't seem to figure out how? Sorry to be annoying with this, I just really want to understand the program better.
#!/usr/bin/python
import random
if __name__=="__main__":
print("Content-type: text/html")
print()
quotes=["The course of true love never did run smooth.", "Life every man holds dear; but the dear man holds honor far more precious dear than life.",
"To thine own self be true, and it must follow, as the night the day, thou canst not then be false to any man.", "Poor and content is rich, and rich enough.",
"If you have tears, prepare to shed them now.", "Words without thoughts never to heaven go."]
pics=["http://ift.tt/22LIsHt", "http://ift.tt/25oX2Xt",
"http://ift.tt/22LIsah", "http://ift.tt/25oX55x",
"http://ift.tt/22LIsXI", "http://ift.tt/1hf2gvt"]
print ("""
<html>
<head>
<title>QOTD: Shakespeare </title>
</head>
<body>
<center>
<img src="%s">
<p>
<font size="12"><b>The quote of the day is:</b></font>
<p>
<table>
<tr>
<td width="500"><font size="6">%s</font>
</td>
</tr>
</table>
</p>
</center>
</body>
</html>
""") % (random.choice(pics), random.choice(quotes))
Aucun commentaire:
Enregistrer un commentaire