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: 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 Subject: Re: Need help with programming in python for class (beginner level) Date: Sun, 01 Dec 2013 17:01:11 -0800 References: 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: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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 "

your total number was:" number "

" > > 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 > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> > > A CGI Script > > """ > 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 "

The total rolled was: "number"

" > > print "

Thanks for playing, " + name + ".

" > print "

You bet the total would be at least " + value + ".

" > print "" > My two "favorites": print '

The total rolled was: %s

' % number [py 2.7+] print('

The total rolled was: {}

'.format(number)) Cheers, -- Speedbird