Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #35916
| References | <2f5053ab-a646-49d3-a569-61468f518b9f@googlegroups.com> <39abb4d2-277a-4ac9-8574-0d3e3751b7ef@googlegroups.com> |
|---|---|
| From | Matt Jones <matt.walker.jones@gmail.com> |
| Date | 2013-01-01 14:46 -0600 |
| Subject | Re: Considering taking a hammer to the computer... |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1531.1357073240.29569.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
rooms_on_floor is being set by the manual input for each floor iterated
over in your for loop. My guess is your total_rooms value equals the rooms
from the last floor you processed. Same goes for the occupied_rooms.
You'll want a separate variable to increment after each occupied_rooms or
rooms_on_floor is received from the user.
something like...:
rooms_on_floor = int(input("Enter the number of rooms on floor: "))
total_rooms += rooms_on_floor
*Matt Jones*
On Tue, Jan 1, 2013 at 2:14 PM, <worldsbiggestsabresfan@gmail.com> wrote:
> OK, thank you all for your help yesterday!
>
> Here's where we are today (using python 3.3.0)
>
> He has everything running well except for the final calculations - he
> needs to be able to total the number of rooms in the hotel, as well as the
> number of occupied rooms. We have tried several different things and can't
> come up with a successful command. Any help you can give will be much
> appreciated!!
>
> Here's what he's got:
>
> #This program will calculate the occupancy rate of a hotel
> floor_number = 0
> rooms_on_floor = 0
> occupied_rooms = 0
> total_rooms = 0
> total_occupied = 0
>
>
>
> number_of_floors = int(input("How many floors are in the hotel?: "))
> while number_of_floors < 1:
> print ("Invalid input! Number must be 1 or more")
> number_of_floors = int(input("Enter the number of floors in the hotel:
> "))
>
> for i in range(number_of_floors):
> 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! Number must be 10 or more")
> 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)
>
> #CALCULATE OCCUPANCY RATE FOR HOTEL
> print()
> total_rooms = sum(rooms_on_floor) #DOESN'T WORK!
> total_occupied = sum(occupied_rooms) #DOESN'T WORK!
> hotel_occupancy = total_occupied / total_rooms
> vacant_rooms = total_rooms - total_occupied
> 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)
> print ("The number of vacant rooms at this hotel is ",vacant_rooms)
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
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