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)

Path csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; '"""': 0.07; 'subject:help': 0.08; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'random': 0.14; '"."': 0.16; '"your': 0.16; 'assignment.': 0.16; 'dice': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:beginner': 0.16; 'subject:class': 0.16; 'subject:programming': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'seems': 0.21; 'command': 0.22; 'import': 0.22; 'print': 0.22; 'header :User-Agent:1': 0.23; 'received:comcast.net': 0.24; 'cheers,': 0.24; 'script': 0.25; 'least': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'along': 0.30; "i'm": 0.30; 'work.': 0.31; 'code': 0.31; 'lines': 0.31; "skip:' 10": 0.31; 'that.': 0.31; 'cgi': 0.31; 'up.': 0.33; 'trouble': 0.34; 'subject: (': 0.35; 'subject:with': 0.35; 'something': 0.35; 'but': 0.35; 'add': 0.35; 'dies': 0.36; 'like,': 0.36; 'done': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'two': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'email addr:gmail.com': 0.63; 'name': 0.63; 'subject:Need': 0.64; 'school': 0.64; 'total': 0.65; 'here': 0.66; 'url:xhtml1': 0.75; 'url:dtd': 0.80; 'rolls': 0.84; 'was:': 0.91; 'write:': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Julio Schwarzbeck <julio@techfuel.net>
Subject Re: Need help with programming in python for class (beginner level)
Date Sun, 01 Dec 2013 17:01:11 -0800
References <e9d18514-1da5-471a-bf39-5f67d3d8fef7@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host c-50-137-22-234.hsd1.wa.comcast.net
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1
In-Reply-To <e9d18514-1da5-471a-bf39-5f67d3d8fef7@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3454.1385946084.18130.python-list@python.org> (permalink)
Lines 49
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1385946084 news.xs4all.nl 15909 [2001:888:2000:d::a6]:54661
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:60851

Show key headers only | 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