Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #35875
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <modulok@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.062 |
| X-Spam-Evidence | '*H*': 0.88; '*S*': 0.00; 'string.': 0.04; 'skip:` 10': 0.05; 'before.': 0.09; 'calculates': 0.09; 'loop.': 0.09; 'reached.': 0.09; 'cc:addr:python-list': 0.10; 'yet.': 0.13; '"break"': 0.16; '#this': 0.16; 'invalid.': 0.16; 'loops': 0.16; 'started:': 0.16; 'input': 0.18; 'trying': 0.21; 'assignment': 0.22; 'int,': 0.22; 'progress.': 0.22; 'stopping': 0.22; 'runs': 0.22; 'cc:2**0': 0.23; 'programming': 0.23; "haven't": 0.23; 'thus': 0.24; 'cc:no real name:2**0': 0.24; 'idea': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'skip:# 10': 0.27; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; 'floor.': 0.29; 'learn,': 0.29; "i'm": 0.29; 'figure': 0.30; 'help,': 0.32; 'print': 0.32; 'asked': 0.33; 'comments': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'done': 0.34; 'faster': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'except': 0.36; 'but': 0.36; 'thank': 0.36; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'things': 0.38; 'nothing': 0.38; 'possible.': 0.38; 'sure': 0.38; 'instead': 0.39; 'little': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'help': 0.40; 'end': 0.40; 'your': 0.60; 'son': 0.60; 'identify': 0.61; 'spending': 0.61; 'telling': 0.61; 'first': 0.61; 'subject:...': 0.63; 'skip:n 10': 0.63; 'love': 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 |
| 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 :cc:content-type; bh=RiOR7vZmljTzIrhd3Bdgq1aLP7j9LfO2vcwyUJTU3gk=; b=fbwxT/57LFWIfedpVHbepOjyv3G6Bp4GjffzM8gOSAnR+jjQc9wR7hS3t/8BcJiSta uWWjUDaCa3bpHrwNJd/nxrP1jO4UisRUTrx8Jr6Ib+ZsCZepiWdNUKMge79EtSVRyWoV WHEpkjME1GZoK60DQ8CzwJFlWf8FcyHHB+GZn1oUa5uz/fhaydNnTZgWEnNkJ6ec17NI bi7p2e/Jffhi6ImDpQYqYxz91DzsfQQNZJCNZ5E4RhggNi5RsFbJX3KBcXptpn4mHKoO af+WnmhJHmfS8UZpD/Wkaz029D0NBAlc4tMvbls5EIOqMDQed1wQ+8Q46Aim1hci/Uzk +vBA== |
| MIME-Version | 1.0 |
| In-Reply-To | <2f5053ab-a646-49d3-a569-61468f518b9f@googlegroups.com> |
| References | <2f5053ab-a646-49d3-a569-61468f518b9f@googlegroups.com> |
| Date | Mon, 31 Dec 2012 20:59:06 -0700 |
| Subject | Re: Considering taking a hammer to the computer... |
| From | Modulok <modulok@gmail.com> |
| To | worldsbiggestsabresfan@gmail.com |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Cc | python-list@python.org |
| 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.1508.1357012755.29569.python-list@python.org> (permalink) |
| Lines | 116 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1357012755 news.xs4all.nl 6875 [2001:888:2000:d::a6]:52468 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:35875 |
Show key headers only | View raw
> 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!
Here's your program with some extra comments to get you started:
#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: ")
# Remember you need to make sure this is an int, just like before.
# number_of_floors = int(input("Enter the number of floors
in the hotel: ")) Right now it's a string.
while number_of_floors > 1:
# This loop runs forever, as number_of_floors never changes. You need
# to do something to `number_of_floors` such as de-increment it e.g:
# `number_of_floors -= 1`, that way we will *eventually* have
# number_of_floors less than 1, thus stopping the loop. A better
# idea would be to use a `for` loop instead of the above `while`
# loop. For example::
#
# for i in range(number_of_floors):
# # blah... do something for each floor. This loop
auto-terminates.
#
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!")
# You might consider telling your user why their input is
# invalid. e.g: "rooms on floor must be greater than 10".
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)
-Modulok-
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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