2016-03-26 7 views
1

TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'TypeError: nicht unterstützte Operandentyp (en) für%: 'NoneType' und 'Tupel' mit Zufallsgenerator?

Ich brauche ein Angebot oder ein Bild zum Drucken anstelle von %s aber kann nicht scheinen, herauszufinden, wie?

#!/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=["https://ebooks.adelaide.edu.au/s/shakespeare/william/portrait.jpg", "http://images.wisegeek.com/william-shakespeare-painting.jpg", 
    "https://mareseosullivan.files.wordpress.com/2012/01/william-shakespeare.jpg", "http://bookhaven.stanford.edu/wp-content/uploads/2010/10/shakespeare-4.jpg", 
    "http://i.telegraph.co.uk/multimedia/archive/02699/shakespeare_2699766b.jpg", "http://www.poetryfoundation.org/uploads/authors/william-shakespeare/448x/william-shakespeare.jpg"] 




    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)) 
+0

@idjaw I Einzug ändern musste hier, um den Code richtig in meiner Frage zu drucken. Kannst du mich wissen lassen, was du geändert hast? –

+0

Ich habe Ihren Code auf Python 2.7 ausgeführt. Als ich es auf Python 3 ausführte, replizierte ich Ihr Problem. Sie sollten jedoch Ihren Einzug in Ihrer Frage wirklich korrigieren, um eine korrekte Darstellung Ihres Codes zu erhalten. – idjaw

Antwort

1

Sie verwenden wahrscheinlich Python 3.X. Der Code, den Sie haben Werke für Python 2.x, aber Sie müssen es wie folgt ändern:

Statt:

print (s) % (x, y) 

Try this:

print (s % (x, y)) 
+0

Vielen Dank !!! –

Verwandte Themen