Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #35866

Re: Considering taking a hammer to the computer...

Date 2012-12-31 19:34 -0500
From Mitya Sirenef <msirenef@lightbird.net>
Subject Re: Considering taking a hammer to the computer...
References <2f5053ab-a646-49d3-a569-61468f518b9f@googlegroups.com> <50E22DEE.8050401@lightbird.net>
Newsgroups comp.lang.python
Message-ID <mailman.1505.1357000496.29569.python-list@python.org> (permalink)

Show all headers | View raw


On 12/31/2012 07:29 PM, Mitya Sirenef wrote:
>
>
> Hi! First I want to note that this task would be easier and better to do
> with a break statement, so it's quite unfortunate that the teacher did
> not cover the right tools (and very basic ones, in fact) and yet given
> this task.
>
> Another question: are you allowed to use functions? (I'm guessing not).
>
> You can do this task much easier if you write it out in pseudo code
> before you go to python code. For example, to convert your existing
> code to pseudo code:
>
> * set floor_number to 0
> * get number of floors from the user
>
> * as long as number of floors is less than 1:
>     * print invalid input
>     * get number of floors from the user
>
> * as long as number of floors is more than 1:
>     * increment floor_number
>
>     * get number of rooms
>     * as long as number of rooms is less than 10:
>         * get number of rooms
>
>     * get occupied_rooms
>     * occupancy_rate = occupied rooms / number of rooms
>
>     * how do we keep track of total rooms and total occupied rooms here??
>
>
> Does it make it easier to think about the logic of the program?
>
>  - mitya
>
>

I forgot to add this:

question = "How many floors are in the hotel?: "
number_of_floors = int(input(question))

while number_of_floors < 1:
     print("Invalid input!")
     number_of_floors = int(input(question))


It's easier to save the question in a variable and use it two
times (and do the same in the next loop); it's not clear
why/if the questions should be different as you're asking
the user for the same thing.

  -m

-- 
Lark's Tongue Guide to Python: http://lightbird.net/larks/

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Considering taking a hammer to the computer... worldsbiggestsabresfan@gmail.com - 2012-12-31 15:42 -0800
  Re: Considering taking a hammer to the computer... Chris Angelico <rosuav@gmail.com> - 2013-01-01 11:08 +1100
  Re: Considering taking a hammer to the computer... Chris Angelico <rosuav@gmail.com> - 2013-01-01 11:09 +1100
  Re: Considering taking a hammer to the computer... Mitya Sirenef <msirenef@lightbird.net> - 2012-12-31 19:29 -0500
  Re: Considering taking a hammer to the computer... Mitya Sirenef <msirenef@lightbird.net> - 2012-12-31 19:34 -0500
  Re: Considering taking a hammer to the computer... Vlastimil Brom <vlastimil.brom@gmail.com> - 2013-01-01 01:36 +0100
  Re: Considering taking a hammer to the computer... worldsbiggestsabresfan@gmail.com - 2012-12-31 17:30 -0800
    Re: Considering taking a hammer to the computer... Mitya Sirenef <msirenef@lightbird.net> - 2012-12-31 21:00 -0500
    Re: Considering taking a hammer to the computer... Tim Chase <python.list@tim.thechases.com> - 2012-12-31 22:41 -0600
    Re: Considering taking a hammer to the computer... Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-01-01 14:35 -0500
  Re: Considering taking a hammer to the computer... Modulok <modulok@gmail.com> - 2012-12-31 20:59 -0700
  Re: Considering taking a hammer to the computer... worldsbiggestsabresfan@gmail.com - 2013-01-01 12:14 -0800
    Re: Considering taking a hammer to the computer... Matt Jones <matt.walker.jones@gmail.com> - 2013-01-01 14:46 -0600
      Re: Considering taking a hammer to the computer... worldsbiggestsabresfan@gmail.com - 2013-01-01 13:57 -0800
      Re: Considering taking a hammer to the computer... worldsbiggestsabresfan@gmail.com - 2013-01-01 13:57 -0800
    Re: Considering taking a hammer to the computer... Chris Angelico <rosuav@gmail.com> - 2013-01-02 09:01 +1100
    Re: Considering taking a hammer to the computer... Dave Angel <d@davea.name> - 2013-01-01 15:28 -0500
    Re: Considering taking a hammer to the computer... Dave Angel <d@davea.name> - 2013-01-01 17:34 -0500
  Re: Considering taking a hammer to the computer... MRAB <python@mrabarnett.plus.com> - 2013-01-01 00:02 +0000

csiph-web