Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!gordon From: John Gordon Newsgroups: comp.lang.python Subject: Re: First python program, syntax error in while loop Date: Fri, 3 May 2013 20:04:00 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 24 Message-ID: References: <24c5856e-a30a-41bd-aa4a-0e594734e1f8@googlegroups.com> NNTP-Posting-Host: panix1.panix.com X-Trace: reader1.panix.com 1367611440 8184 166.84.1.1 (3 May 2013 20:04:00 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Fri, 3 May 2013 20:04:00 +0000 (UTC) User-Agent: nn/6.7.3 Xref: csiph.com comp.lang.python:44685 In ryankoch38@gmail.com writes: > I've got it working! I'm really enjoying python :) But now i'd like to make it break out of the while loop when the user guesses more than 5 numbers and fails The "Congratulations" message is inside the while loop; that's why it always prints. To break after five guesses, you could change the while loop to this: while (guess != number) and (tries < 5): And then after the while loop, put this if statement: if (tries < 5): print "\nCongratulations! You guessed my number in", tries, "tries" else: print "Sorry, you lost!" -- John Gordon A is for Amy, who fell down the stairs gordon@panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies"