Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #60851

Re: Need help with programming in python for class (beginner level)

From Julio Schwarzbeck <julio@techfuel.net>
Subject Re: Need help with programming in python for class (beginner level)
Date 2013-12-01 17:01 -0800
References <e9d18514-1da5-471a-bf39-5f67d3d8fef7@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.3454.1385946084.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 11/29/2013 04:31 PM, farhanken@gmail.com wrote:
> It's for a school assignment. Basically, I need to roll 5 dies with 6 sides each. So basically, 6 random numbers. That part is easy. Then I need to add it up. Ok, done that. However, I also need to say something along the lines of "your total number was X". That's what I'm having trouble with. I added the dice rolls together and put them into a variable I called "number" but it seems to glitch out that variable is in any command other than "print number". Like, if I try to write:
>
> print "<p>your total number was:" number "</p>"
>
> It just doesn't work.
>
> Here is my code so far:
>
>
> import cgi
>
> form = cgi.FieldStorage()
> name = form.getvalue("name")
> value = form.getvalue("value")
>
>
> 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>A CGI Script</title>
> </head><body>
> """
> import random
>
> 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)
> print die1, die2, die3, die4, die5
> number = die1 + die2 + die3 + die4 + die5
> print "<p>The total rolled was: "number" </p>"
>
> print "<p>Thanks for playing, "  + name +  ".</p>"
> print "<p>You bet the total would be at least " + value + ".</p>"
> print "</body></html>"
>

My two "favorites":

print '<p>The total rolled was: %s </p>' % number
[py 2.7+] print('<p>The total rolled was: {} </p>'.format(number))

Cheers,

-- Speedbird

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Need help with programming in python for class (beginner level) farhanken@gmail.com - 2013-11-29 16:31 -0800
  Re: Need help with programming in python for class (beginner level) Johannes Findeisen <mailman@hanez.org> - 2013-11-30 01:38 +0100
  Re: Need help with programming in python for class (beginner level) Eduardo A. Bustamante López <dualbus@gmail.com> - 2013-11-29 16:45 -0800
  Re: Need help with programming in python for class (beginner level) Johannes Findeisen <mailman@hanez.org> - 2013-11-30 01:49 +0100
  Re: Need help with programming in python for class (beginner level) Tim Chase <python.list@tim.thechases.com> - 2013-11-29 18:53 -0600
  Re: Need help with programming in python for class (beginner level) Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-30 00:59 +0000
  Re: Need help with programming in python for class (beginner level) Tim Chase <python.list@tim.thechases.com> - 2013-11-29 19:06 -0600
  Re: Need help with programming in python for class (beginner level) Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-30 01:08 +0000
  Re: Need help with programming in python for class (beginner level) Johannes Findeisen <mailman@hanez.org> - 2013-11-30 02:16 +0100
  Re: Need help with programming in python for class (beginner level) Julio Schwarzbeck <julio@techfuel.net> - 2013-12-01 17:01 -0800

csiph-web