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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'python.': 0.02; 'subject:error': 0.03; 'elif': 0.05; 'tries': 0.07; 'subject:while': 0.09; 'random': 0.14; '"guess': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'guess.': 0.16; 'loops': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'once.': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'script?': 0.16; 'subject:program': 0.16; 'you"': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'header:In-Reply-To:1': 0.27; "i'm": 0.30; 'indentation': 0.31; 'guess': 0.33; 'received:84': 0.35; 'that!': 0.36; 'next': 0.36; 'should': 0.36; 'wrong': 0.37; 'project': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'lower': 0.61; 'took': 0.61; 'first': 0.61; 'email addr:gmail.com': 0.63; 'real': 0.63; 'number:': 0.66; 'between': 0.67; 'header:Reply-To:1': 0.67; 'press': 0.70; 'reply- to:no real name:2**0': 0.71; 'secret': 0.74; 'subject:First': 0.74; '100': 0.79; 'guessed': 0.84; 'number):': 0.84; 'reply- to:addr:python.org': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=JsTI8qIC c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=7AxPfEIvyrUA:10 a=eOLh6Stwm0kA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=oOVRW_tk6tIA:10 a=pGLkceISAAAA:8 a=Re2l7rFBaKOtFToArQgA:9 a=SBZnjQHYYdoQ4uAn:21 a=3R9M-cS7ROPrRRp6:21 a=wPNLvfGTeEIA:10 a=MSl-tDqOz04A:10 X-AUTH: mrabarnett:2500 Date: Fri, 03 May 2013 18:36:52 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 MIME-Version: 1.0 To: python-list@python.org Subject: Re: First python program, syntax error in while loop References: <24c5856e-a30a-41bd-aa4a-0e594734e1f8@googlegroups.com> In-Reply-To: <24c5856e-a30a-41bd-aa4a-0e594734e1f8@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org 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: 61 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1367602615 news.xs4all.nl 15870 [2001:888:2000:d::a6]:33577 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44674 On 03/05/2013 18:18, ryankoch38@gmail.com 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 :") > > while (guess != number): > if (guess > number): > number = int(raw_input("Sorry, my number is lower than that! \n Try again:") > tries += 1 > 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!" > > 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 > Indentation in important in Python. Also, "else if" should be "elif", and you ask for a guess only once. title = "Guess my number game:" print title.title() raw_input("Press any key to continue..") import random tries = 0 number = random.randrange(99) + 1 # Ask for first guess. guess = int(raw_input("Guess my number! Secret - It is between 1 and 100 :") while guess != number: if guess > number: number = int(raw_input("Sorry, my number is lower than that! \n Try again:") tries += 1 elif guess < number: number = int(raw_input("Sorry, my number is higher than that! \n Try again:") tries += 1 # Ask for next guess. guess = int(raw_input("Guess my number! Secret - It is between 1 and 100 :") print "Congratulations, you guessed my number! \n And it only took you" tries "tries!" raw_input("\n\n Press any key to exit..")