Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!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.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'differently': 0.07; 'problem:': 0.07; 'repeated': 0.07; 'python': 0.09; 'behave': 0.09; 'exceeds': 0.09; 'integer,': 0.09; 'integers': 0.09; 'iterate': 0.09; '(other': 0.16; '1).': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'guessing': 0.16; 'string': 0.17; 'wrote:': 0.17; 'certainly': 0.17; 'integer': 0.17; '(in': 0.18; 'jan': 0.18; 'mention': 0.23; 'second': 0.24; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'right.': 0.27; 'skip:# 10': 0.27; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; 'lines': 0.28; 'chris': 0.28; 'crash': 0.29; 'loop,': 0.29; 'this.': 0.29; "i'm": 0.29; 'error': 0.30; 'figure': 0.30; 'sense': 0.31; '(and': 0.32; 'asking': 0.32; 'print': 0.32; "aren't": 0.33; 'ordered': 0.33; 'to:addr:python-list': 0.33; 'another': 0.33; 'version': 0.34; 'received:google.com': 0.34; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'compare': 0.36; 'should': 0.36; 'two': 0.37; 'quite': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'son': 0.60; 'range': 0.60; '(that': 0.62; 'between': 0.63; 'different': 0.63; 'subject:...': 0.63; 'skip:n 10': 0.63; 'more': 0.63; 'here': 0.65; 'learned': 0.65; "'for'": 0.84; '2013': 0.84; 'around,': 0.84; 'floors': 0.84; 'rooms': 0.84; 'hand,': 0.97 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=cgVWezmwsL0ch0XeOddSb/72kjMYStYKLcjj4gv2wNQ=; b=XIwAge5ZfSMWFqDX7xpq3Zjg3Fbkoqkfe+644eXV+7N21CtiVICFqMAqqIemtgS4Wq 9QD+U166EpuhIiyscP7hjFo/BxFrrcV8q8IU9+Q+QXWDqnlLxdrmvLndLIx8HYQAzWlS RtL8lvdncadeqlUhLwLYxBb7cvUOLg2g9KJ/BeNyW9B3icS/vqW63YS+zPyuy/hE1HJQ HxJ/OsMjjMUp1rKWDXpXK7gpA/jItzZ3eOOIjQkHM9muYgiCL+zp4Qy3uGabR0VcjmSz TfUEsidOI83wadB7UebEKspgGXP2vRkfMkibd5sQIZw+ln3Xv1lYBC2z22UQ9TBoX5Dg fQBA== MIME-Version: 1.0 In-Reply-To: <2f5053ab-a646-49d3-a569-61468f518b9f@googlegroups.com> References: <2f5053ab-a646-49d3-a569-61468f518b9f@googlegroups.com> Date: Tue, 1 Jan 2013 11:08:17 +1100 Subject: Re: Considering taking a hammer to the computer... From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1356998899 news.xs4all.nl 6920 [2001:888:2000:d::a6]:36547 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35862 On Tue, Jan 1, 2013 at 10:42 AM, wrote: > while number_of_floors > 1: > floor_number = floor_number + 1 > print() > print ("For floor #",floor_number) > rooms_on_floor = int(input("How many rooms are on the floor ?: " )) > while rooms_on_floor < 10: > print ("Invalid input!") > rooms_on_floor = int(input("Enter the number of rooms on floor: ")) You have a loop here that can never terminate, because number_of_floors never changes. There are a couple of solutions to this. One would be to compare floor_number to number_of_floors, and stop the loop once the one exceeds the other; another (and more Pythonic) way would be to use a 'for' loop, and iterate over the range of numbers from 1 to the number of floors. See if your son has learned about range(), if so he should be able to figure it out from that clue. One tip: When you're asking a question like this, mention what Python version you're using. I'm guessing it's Python 3.something, but that might not be right. If it is indeed Python 3, then the repeated question here will be a problem: number_of_floors = int(input("How many floors are in the hotel?: ")) while number_of_floors < 1: print ("Invalid input!") number_of_floors = input("Enter the number of floors in the hotel: ") Note the difference between the two request lines (other than the prompt, which is insignificant). The second time around, you're not turning it into an integer, so that will crash (in Python 3) with the error that strings and integers aren't ordered (that is, that it makes no sense to ask whether a string is less than the integer 1). Python 2, on the other hand, will behave very differently here, as input() has a quite different meaning (and one that you almost certainly do NOT want). Chris Angelico