Considering taking a hammer to the computer...
Mitya Sirenef
msirenef at lightbird.net
Mon Dec 31 19:34:49 EST 2012
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/
More information about the Python-list
mailing list