import cgi formData = cgi.FieldStorage() import random visitorName = formData["formName"].value visitorGuess = formData["formGuess"].value die1 = random.randint (1, 6) die2 = random.randint (1, 6) die3 = random.randint (1, 6) die4 = random.randint (1, 6) die5 = random.randint (1, 6) total = int(die1+die2+die3+die4+die5) print "Content-type: text/html" print print """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Dice Game</title> </head> <body> <h1>Dice Game</h1>""" print "<p>Thanks for playing, " +visitorName+ ". </p>" print "<p>You bet the total would be " +str(visitorGuess)+ ". </p>" print "<p>The total rolled was " +str(total)+ ".</p>" if die1==1: print "<p><img src='Images/dice-1.png' alt='dice1' /></p>" elif die1==2: print "<p><img src='Images/dice-2.png' alt='dice2' /></p>" elif die1==3: print "<p><img src='Images/dice-3.png' alt='dice3' /></p>" elif die1==4: print "<p><img src='Images/dice-4.png' alt='dice4' /></p>" elif die1==5: print "<p><img src='Images/dice-5.png' alt='dice5' /></p>" if die2==1: print "<p><img src='Images/dice-1.png' alt='dice1' /></p>" elif die2==2: print "<p><img src='Images/dice-2.png' alt='dice2' /></p>" elif die2==3: print "<p><img src='Images/dice-3.png' alt='dice3' /></p>" elif die2==4: print "<p><img src='Images/dice-4.png' alt='dice4' /></p>" elif die2==5: print "<p><img src='Images/dice-5.png' alt='dice5' /></p>" if die3==1: print "<p><img src='Images/dice-1.png' alt='dice1' /></p>" elif die3==2: print "<p><img src='Images/dice-2.png' alt='dice2' /></p>" elif die3==3: print "<p><img src='Images/dice-3.png' alt='dice3' /></p>" elif die3==4: print "<p><img src='Images/dice-4.png' alt='dice4' /></p>" elif die3==5: print "<p><img src='Images/dice-5.png' alt='dice5' /></p>" if die4==1: print "<p><img src='Images/dice-1.png' alt='dice1' /></p>" elif die4==2: print "<p><img src='Images/dice-2.png' alt='dice2' /></p>" elif die4==3: print "<p><img src='Images/dice-3.png' alt='dice3' /></p>" elif die4==4: print "<p><img src='Images/dice-4.png' alt='dice4' /></p>" elif die4==5: print "<p><img src='Images/dice-5.png' alt='dice5' /></p>" if die5==1: print "<p><img src='Images/dice-1.png' alt='dice1' /></p>" elif die5==2: print "<p><img src='Images/dice-2.png' alt='dice2' /></p>" elif die5==3: print "<p><img src='Images/dice-3.png' alt='dice3' /></p>" elif die5==4: print "<p><img src='Images/dice-4.png' alt='dice4' /></p>" elif die5==5: print "<p><img src='Images/dice-5.png' alt='dice5' /></p>" if total == visitorGuess: print "<p> You Won!!! </p>" elif total != visitorGuess: print "<p> Sorry you lost. </p>" print """ </body> </html>"""
I need to be able to print out an image of the 5 random dice results, but I need to do it in a more efficient way than I have in the coding above. here are the instructions from my assignment bellow. I don't really understand what to do.
Step 5 – Dice Images
• However, you can create a more efficient
algorithm to display the 5 images of the dice
• This efficient algorithm will have only one
<img> statement and will make use of an
iterative Python statement
• This single <img> statement will look a bit
different from the one above
• You must create this efficient algorithm


Sign In
Create Account

Back to top









