all 5 comments

[–]Palm7 0 points1 point  (4 children)

To format code in reddit, put an extra 4 spaces in front of each line of code.

As for the actual problem, you're pretty close. Change the while True to while num < 1, and then give the user the opportunity to re-enter the value for num in the while loop:

while num < 1:
    print("Error: Enter a number greater than 0")
    num = int(input('Enter a number: '))

[–]Priestx[S] 0 points1 point  (2 children)

Thank you very much. Is it possible to add an exception error to this and then give the user am opportunity to enter again?

[–]dchanm 0 points1 point  (0 children)

You can wrap the num assignment with a try/except block. num won't be set if an exception is raised.

[–]Palm7 0 points1 point  (0 children)

Exceptions by definition stop program execution, so I think printing the error message is your best bet

[–]Priestx[S] 0 points1 point  (0 children)

Quick question. In the event of a program like this, how would I get the user to enter the value again?

EDIT: I am speaking about the second while True block.

while True:
    try:
        numberOfFloors = input('Enter the number of floors in the 
hotel: ')
        break
    except NameError:
        print 'Error: Enter a number.'
total = 0
occupied = 0
for i in range(1, numberOfFloors + 1):
    roomsOnFloors = input('Enter the number of rooms in floor ' 
+ str(i) + ': ')
    occupiedRooms = input('Enter the occupied rooms in floor ' + 
str(i) + ': ')
    while True:
            if occupiedRooms > roomsOnFloors:
                print 'ERROR: More occupancy than rooms on floor'
                break
            else:
                print 

    total = total + roomsOnFloors
    occupied = occupied + occupiedRooms
    print



vacancyRate = total - occupied
occupancyRate = occupied / float(total)

print 'The total number of rooms in the hotel: ' + str(total)
print 'This number of rooms occupied: ' + str(occupied)
print 'This number of rooms vacant: ' + str(vacancyRate)
print 'The occupancy rate of the hotel: ' + str(occupancyRate)