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


Groups > comp.lang.python > #35867

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

References <2f5053ab-a646-49d3-a569-61468f518b9f@googlegroups.com>
Date 2013-01-01 01:36 +0100
Subject Re: Considering taking a hammer to the computer...
From Vlastimil Brom <vlastimil.brom@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1506.1357000604.29569.python-list@python.org> (permalink)

Show all headers | View raw


2013/1/1  <worldsbiggestsabresfan@gmail.com>:
> 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!
> --
> http://mail.python.org/mailman/listinfo/python-list

Hi,
if "break" isn't allowed, you can add the appropriate condition to the
while construct
>>> i=0
>>> while i < 4:
...     print i
...     i = i + 1
...
0
1
2
3
>>>

or you can use the for-loops based on the previously determined number
of the floors and rooms respectively.
let's hope "range(...)" is allowed - the usual idiom is e.g.:
>>> for i in range(4):
...     print i
...
0
1
2
3
>>>

Note, that the indexing in python is zero-based (which also applies
for range by default); the range doesn't include the given upper
stop-value
http://docs.python.org/release/3.3.0/library/stdtypes.html#range

Depending on the assignment and on the interpretation of the
ground-floor ("zeroth-floor"), you may need to account for this (you
can also pass the "start" value to range(...) ).

the totals can be collected simply by incrementing the respective
numbers with each floor within the loop.

hth,
  vbr

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