Velocity Reviews > Considering taking a hammer to the computer...

# Considering taking a hammer to the computer...

Tim Chase
Guest
Posts: n/a

 01-01-2013
On 12/31/12 19:30, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Here is what I've learned:

[snip]
> 4) It's New Year's Eve and I'm trying to learn Python...?

Can't think of a much better way to spend New Year's Eve, unless
you're learning Python while also watching fireworks.

-tkc

Dennis Lee Bieber
Guest
Posts: n/a

 01-01-2013
On Mon, 31 Dec 2012 22:41:54 -0600, Tim Chase
<(E-Mail Removed)> declaimed the following in
gmane.comp.python.general:

> On 12/31/12 19:30, (E-Mail Removed) wrote:
> > Here is what I've learned:

> [snip]
> > 4) It's New Year's Eve and I'm trying to learn Python...?

>
> Can't think of a much better way to spend New Year's Eve, unless
> you're learning Python while also watching fireworks.
>

Using Python to control a fireworks launch sequencer?
--
Wulfraed Dennis Lee Bieber AF6VN
(E-Mail Removed) HTTP://wlfraed.home.netcom.com/

worldsbiggestsabresfan@gmail.com
Guest
Posts: n/a

 01-01-2013
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 needsto 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 comeup 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)

Dave Angel
Guest
Posts: n/a

 01-01-2013
On 01/01/2013 03:14 PM, (E-Mail Removed) 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!!

There are two ways to get those totals, depending on whether you know
how to work lists or not. If you do, then you should make a list of
occupied_rooms, and sum() it at the end, and make a list of
rooms_on_flow, and sum that at the end.

But as you discovered, sum() won't work on an int (BTW, you should give
the entire traceback instead of saying "doesn't work". In this case, it
was obvious, but it might not be.)

On the other hand, if you don't know what a list is, then you need to
accumulate those numbers as you go. Either way, you need extra
variables to represent the whole hotel, and you need to do something
inside the loop to adjust those variables.

--

DaveA

Matt Jones
Guest
Posts: n/a

 01-01-2013
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, <(E-Mail Removed)> 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
>

worldsbiggestsabresfan@gmail.com
Guest
Posts: n/a

 01-01-2013
That's it!!! Thank you, Matt!! project done!

Thank you all, very much.

Happy New Year!

worldsbiggestsabresfan@gmail.com
Guest
Posts: n/a

 01-01-2013
That's it!!! Thank you, Matt!! project done!

Thank you all, very much.

Happy New Year!

Chris Angelico
Guest
Posts: n/a

 01-01-2013
On Wed, Jan 2, 2013 at 7:14 AM, <(E-Mail Removed)> wrote:
> floor_number = 0
> for i in range(number_of_floors):
> floor_number = floor_number + 1

Matt's already given you the part you need (and it seems to have
worked for you, yay!). Side point: Are you aware that i and
floor_number are always going to have the same value? You can simplify
this down to:

for floor_number in range(number_of_floors):

ChrisA

Dave Angel
Guest
Posts: n/a

 01-01-2013
On 01/01/2013 05:01 PM, Chris Angelico wrote:
> On Wed, Jan 2, 2013 at 7:14 AM, <(E-Mail Removed)> wrote:
>> floor_number = 0
>> for i in range(number_of_floors):
>> floor_number = floor_number + 1

> Matt's already given you the part you need (and it seems to have
> worked for you, yay!). Side point: Are you aware that i and
> floor_number are always going to have the same value? You can simplify
> this down to:
>
> for floor_number in range(number_of_floors):
>
> ChrisA

Actually, floor_number is one higher. The easiest way to fix that is to

for floor_number in range(1, 1+number_of_floors):

Naturally, in some hotels that might not have any rooms on one of the
floors. Divide by zero.

--

DaveA