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


Groups > comp.lang.python > #35865

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

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nntp-feed.chiark.greenend.org.uk!ewrotcd!news.nosignal.org!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <msirenef@lightbird.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.056
X-Spam-Evidence '*H*': 0.89; '*S*': 0.00; 'python': 0.09; 'calculates': 0.09; 'logic': 0.09; 'python:': 0.09; 'reached.': 0.09; 'yet.': 0.13; '"break"': 0.16; '#this': 0.16; "(i'm": 0.16; 'guessing': 0.16; 'increment': 0.16; 'loops': 0.16; 'program?': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'task.': 0.16; 'wrote:': 0.17; 'input': 0.18; 'code.': 0.20; 'trying': 0.21; 'hey': 0.21; 'assignment': 0.22; 'progress.': 0.22; 'programming': 0.23; 'task': 0.23; "haven't": 0.23; 'header :In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'skip:# 10': 0.27; 'question': 0.27; 'floor.': 0.29; 'learn,': 0.29; 'question:': 0.29; 'convert': 0.29; "i'm": 0.29; 'basic': 0.30; 'figure': 0.30; 'code': 0.31; '(and': 0.32; 'help,': 0.32; 'print': 0.32; 'asked': 0.33; 'ones,': 0.33; 'to:addr:python- list': 0.33; 'code:': 0.33; 'another': 0.33; "can't": 0.34; 'done': 0.34; 'faster': 0.35; 'pm,': 0.35; 'except': 0.36; 'but': 0.36; 'thank': 0.36; 'does': 0.37; 'quite': 0.37; 'subject:: ': 0.38; 'easier': 0.38; 'things': 0.38; 'nothing': 0.38; 'possible.': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'little': 0.39; 'skip:" 10': 0.40; 'received:192.168': 0.40; 'help': 0.40; 'end': 0.40; 'think': 0.40; 'your': 0.60; 'son': 0.60; 'identify': 0.61; 'spending': 0.61; 'first': 0.61; 'subject:...': 0.63; 'skip:n 10': 0.63; 'email addr:gmail.com': 0.63; 'love': 0.63; 'more': 0.63; 'making': 0.64; 'great': 0.64; 'here': 0.65; 'taking': 0.65; 'total': 0.65; 'floor,': 0.65; 'hours': 0.66; 'believe': 0.69; 'calculations': 0.84; 'floors': 0.84; 'inch': 0.84; 'occupancy': 0.84; 'occupied': 0.84; 'rooms': 0.84; 'taught': 0.97
Date Mon, 31 Dec 2012 19:29:34 -0500
From Mitya Sirenef <msirenef@lightbird.net>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121011 Thunderbird/16.0.1
MIME-Version 1.0
To python-list@python.org
Subject Re: Considering taking a hammer to the computer...
References <2f5053ab-a646-49d3-a569-61468f518b9f@googlegroups.com>
In-Reply-To <2f5053ab-a646-49d3-a569-61468f518b9f@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
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1504.1357000185.29569.python-list@python.org> (permalink)
Lines 112
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1357000185 news.xs4all.nl 6911 [2001:888:2000:d::a6]:45766
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:35865

Show key headers only | View raw


On 12/31/2012 06:42 PM, worldsbiggestsabresfan@gmail.com wrote:
> Hey :)
 >
 > I'm trying to help my son with an assignment and spending hours 
making an inch of progress. I know nothing about programming and I'm 
trying to learn, on my own, at a rate faster than possible. I would love 
a little help!
 >
 > My son is taking an introductory course and his assignment is to use 
the loops for and while to create a program which calculates a hotel's 
occupancy rate. He has managed all of the "inputs" but needs help with 
the following:
 >
 > 1) The first question asked is how many floors are in the hotel - and 
then the questions are asked floor by floor. We can't figure out how to 
get the program to stop questioning when the number of floors is reached.
 >
 > 2) He has programmed specific calculations for each floor, and now 
needs to have calculations for the entire hotel based on the input about 
each floor.
 >
 >
 > Here is what he has done so far:
 >
 >
 > #This program will calculate the occupancy rate of a hotel
 > floor_number = 0
 >
 >
 > 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: ")
 > 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: "))
 >
 > occupied_rooms = int(input("How many rooms on the floor are 
occupied?: "))
 >
 > #CALCULATE OCCUPANCY RATE FOR FLOOR
 > occupancy_rate = occupied_rooms / rooms_on_floor
 > print ("The occupancy rate for this floor is ",occupancy_rate)
 >
 >
 >
 > The following is what we believe needs to go in the program at the 
end except we can't figure out how to calculate it and make it all work 
:/ (alot of the terms have nothing at all to identify them yet...)
 >
 > hotel_occupancy = total_occupied / total_rooms
 > print ("The occupancy rate for this hotel is ",hotel_occupancy)
 > print ("The total number of rooms at this hotel is ",total_rooms)
 > print ("The number of occupied rooms at this hotel is ",total_occupied)
 > vacant_rooms = total_rooms - total_occupied
 > print ("The number of vacant rooms at this hotel is ",vacant_rooms)
 >
 > We've searched and read and we found things about the "break" and 
"pass" commands but his teacher will not allow them because they haven't 
been taught yet.
 >
 > If you have any ideas and can take a minute to help, that would be 
great :)
 >
 > Thank you!


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



-- 
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