Python Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • m4sh1m4ro
    New Member
    • Mar 2007
    • 2

    #1

    Python Help

    Help please i'm new to python !


    Script Error
    There was an error with your script and it didn't exit properly.

    This was its output:

    File "/home/kml16/public_html/lab8b/hockey5.py", line 15
    <form action="hockey5 .py">
    ^
    SyntaxError: invalid syntax
    (Error code: 1)

    This
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by m4sh1m4ro
    Help please i'm new to python !


    Script Error
    There was an error with your script and it didn't exit properly.

    This was its output:

    File "/home/kml16/public_html/lab8b/hockey5.py", line 15
    <form action="hockey5 .py">
    ^
    SyntaxError: invalid syntax
    (Error code: 1)

    This
    Looks like you are mixing CGI? script into you python script improperly.
    It's hard to tell, though, because you have not posted any of the code.
    Please read "REPLY GUIDELINES" to learn how to use CODE tags and give a snippet to go on. Thanks for joining the Python Forum on TheScripts.com.

    Comment

    • m4sh1m4ro
      New Member
      • Mar 2007
      • 2

      #3
      sorry about that.
      here's the code
      thanks.


      Code:
      # A program that will predict Hockey scores
      import cgi
      form = cgi.FieldStorage()
      import random
      
      print """Content-type: text/html
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
      	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
      <html><head>
      <title> Predicting Hockey Scores </title>
      </head><body>
      """
      	<form action="hockey5.py">
      	
      	    <p> Enter the first team's name: 
      	    	<input type="text" name="team1" />
      	    </p>
      	    <p> Enter the second team's name:
      	     	<input type="text" name="team2" />
      	    </p>
      	    <p> Enter the maximum score value: 
      	     	<input type="text" name="maximum" />
      	    </p>
      	    <p> Enter the minimum score value:
      	    	<input type="text" name="minimum" />
      	    </p>
      	    <p>
      		<input type="submit" value="calculate" />
      	    </p>
      	</form>
      
      
      if form["maximum"].value == form["minimum"].value:
          print "<p>The scores you have entered are the same values, please refresh the page and try again </p>"
      
      minimum = int(form["minimum"].value)
      maximum = int(form["maximum"].value)
      
      score1 = random.randiant(minimum, maximum)
      score2 = random.randint(minimum, maximum)
      
      while score1 == score2:
          score1 = random.randint(minimum, maximum)
          score2 = random.randint(minimum, maximum)
          
      print "<p>The final score will be: " + form["team1"].value + "(" + str(score1) +")   " + form["team2"].value + "(" + str(score2) + ")</p>"
      print """
      </body>
      </html>
      """
      
      # It will then print out the final result
      print "The final score will be: " + team1 + "(" + str(score1) +")   " + team2 + "(" + str(score2) + ")"
      Last edited by bartonc; Mar 27 '07, 10:59 PM. Reason: added [code][/code] tags

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by m4sh1m4ro
        sorry about that.
        here's the code
        thanks.
        The code, but no CODE tags...
        I don't know the cgi interface, but I can tell you that your tripple quotes may be out of place:
        Code:
        print """Content-type: text/html
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
        	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
        <html><head>
        <title> Predicting Hockey Scores </title>
        </head><body>
        
        	<form action="hockey5.py">
        	
        	    <p> Enter the first team's name: 
        	    	<input type="text" name="team1" />
        	    </p>
        	    <p> Enter the second team's name:
        	     	<input type="text" name="team2" />
        	    </p>
        	    <p> Enter the maximum score value: 
        	     	<input type="text" name="maximum" />
        	    </p>
        	    <p> Enter the minimum score value:
        	    	<input type="text" name="minimum" />
        	    </p>
        	    <p>
        		<input type="submit" value="calculate" />
        	    </p>
        	</form>
        """
        Now python wont try to execute "<form action="hockey5 .py">" and throw an error at you.

        Comment

        • ghostdog74
          Recognized Expert Contributor
          • Apr 2006
          • 511

          #5
          Originally posted by m4sh1m4ro
          sorry about that.
          here's the code
          thanks.


          Code:
          # A program that will predict Hockey scores
          import cgi
          form = cgi.FieldStorage()
          import random
          
          print """Content-type: text/html
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
          	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
          <html><head>
          <title> Predicting Hockey Scores </title>
          </head><body>
          """
          	<form action="hockey5.py">
          	
          	    <p> Enter the first team's name: 
          	    	<input type="text" name="team1" />
          	    </p>
          	    <p> Enter the second team's name:
          	     	<input type="text" name="team2" />
          	    </p>
          	    <p> Enter the maximum score value: 
          	     	<input type="text" name="maximum" />
          	    </p>
          	    <p> Enter the minimum score value:
          	    	<input type="text" name="minimum" />
          	    </p>
          	    <p>
          		<input type="submit" value="calculate" />
          	    </p>
          	</form>
          
          
          if form["maximum"].value == form["minimum"].value:
              print "<p>The scores you have entered are the same values, please refresh the page and try again </p>"
          
          minimum = int(form["minimum"].value)
          maximum = int(form["maximum"].value)
          
          score1 = random.randiant(minimum, maximum)
          score2 = random.randint(minimum, maximum)
          
          while score1 == score2:
              score1 = random.randint(minimum, maximum)
              score2 = random.randint(minimum, maximum)
              
          print "<p>The final score will be: " + form["team1"].value + "(" + str(score1) +")   " + form["team2"].value + "(" + str(score2) + ")</p>"
          print """
          </body>
          </html>
          """
          
          # It will then print out the final result
          print "The final score will be: " + team1 + "(" + str(score1) +")   " + team2 + "(" + str(score2) + ")"

          bring your triple quotes """ after the "</head><body>" all the way to the last </form>

          Comment

          Working...