Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'subject:error': 0.03; 'causing': 0.04; 'syntax': 0.04; 'error:': 0.07; 'see.': 0.07; 'tries': 0.07; 'arguments': 0.09; 'executed': 0.09; 'fixed,': 0.09; 'subject:while': 0.09; 'cc:addr:python- list': 0.11; 'random': 0.14; '"guess': 0.16; '"while"': 0.16; 'blocks': 0.16; 'loop.': 0.16; 'loops': 0.16; 'readable': 0.16; 'script?': 0.16; 'subject:program': 0.16; 'you"': 0.16; 'subject:python': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'trying': 0.19; 'import': 0.22; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'error': 0.23; "haven't": 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'points': 0.29; "doesn't": 0.30; 'errors': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'fixing': 0.31; 'indentation': 0.31; 'figure': 0.32; 'another': 0.32; 'fri,': 0.33; 'guess': 0.33; 'level.': 0.33; 'sense': 0.34; 'received:google.com': 0.35; 'that!': 0.36; "i'll": 0.36; 'wrong': 0.37; 'project': 0.37; 'pm,': 0.38; 'above,': 0.60; 'up,': 0.60; 'lower': 0.61; 'took': 0.61; 'first': 0.61; 'here:': 0.62; "you'll": 0.62; 'real': 0.63; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'here': 0.66; 'between': 0.67; 'press': 0.70; 'secret': 0.74; 'subject:First': 0.74; '100': 0.79; 'guessed': 0.84; 'number):': 0.84; 'yourself,': 0.95; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=DCbmXvWgqv8eOtWvKa7SP7jQxZcwBtd20jDa2bfqw0g=; b=ag63YoZq6MEOQkpyRvFNviRE7KQHiQ7qojfQIUCNWyQq96DJt3GRpuRmFuTRpelQVE n0dfRI6bMyX4RhQZJqMZWzQqfBolrAlh0Qt4xauGPjvkglJXC6kqfHQWgH0PiiX2kxwX xaYUcx3lnwv+ghNmpCuh51PMDLg1PArM7izdnlcugIUXLGf6u2J98FAgJ3ZEciIpUcdn 2R7tsu+oG+nQsGMwPQR1Fsu4TPBL6gmaD/LPBY+pkcQJu49el+jklvSWnYnLE3SWiufY 3946qBtRPFtxnwF+rzsvGL1tq0EtiwHgbTvfAqsa2mtFjA+i9lXOS1BodDfjoUaxcxCg 0TKQ== X-Received: by 10.205.101.65 with SMTP id cz1mr3914957bkc.124.1367602679586; Fri, 03 May 2013 10:37:59 -0700 (PDT) MIME-Version: 1.0 Sender: zachary.ware@gmail.com In-Reply-To: <24c5856e-a30a-41bd-aa4a-0e594734e1f8@googlegroups.com> References: <24c5856e-a30a-41bd-aa4a-0e594734e1f8@googlegroups.com> From: Zachary Ware Date: Fri, 3 May 2013 12:37:39 -0500 X-Google-Sender-Auth: gHZCSCOyvc9Ri2m3jhEOnCtXRww Subject: Re: First python program, syntax error in while loop To: ryankoch38@gmail.com Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org 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: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1367602686 news.xs4all.nl 15906 [2001:888:2000:d::a6]:34382 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44676 On Fri, May 3, 2013 at 12:18 PM, wrote: > title = "Guess my number game:" > print title.title() > raw_input("Press any key to continue..") > > import random > > tries = 0 > number = random.randrange(99) + 1 > guess = int(raw_input("Guess my number! Secret - It is between 1 and 100 :") First up, there's a missing ) on each call to int(), which is causing the syntax error you see. The error points at "while" because "while" doesn't make sense in the call to int(). > > while (guess != number): > if (guess > number): After fixing the error above, you'll have another one here: you haven't indented the block to be executed in the while loop. Indentation is important in Python, it delimits code blocks and makes things more readable for people. > number = int(raw_input("Sorry, my number is lower than that! \n Try again:") > tries += 1 There's also another indentation error here: everything in the same block has to be indented to the same level. > else if (guess < number): > number = int(raw_input("Sorry, my number is higher than that! \n Try again:") > tries += 1 > print "Congratulations, you guessed my number! \n And it only took you" tries "tries!" And here will be another syntax error: you have to separate your arguments to 'print' with commas. > > raw_input("\n\n Press any key to exit..") > > ## what is wrong with this script? I'm just trying to understand while loops and ## this is not a real project :P Once you have those errors fixed, I'll bet I can guess your number on the second try every time. I'll let you figure out why yourself, though ;).