couple issues with my code I need help working out.
Code:
import Hotels
htl_1= Hotels.Hotels(111,100,1,1)
htl_2= Hotels.Hotels(112,200,2,1)
htl_3= Hotels.Hotels(113,250,2,2)
htl_4= Hotels.Hotels(114,300,3,2)
htl_5= Hotels.Hotels(115,350,3,3)
feeInput=input('Enter maximum per night fee: ')
roomInput=input('Enter minimum number of bedrooms: ')
bathInput=input('Enter minimum number of baths: ')
header='{:10} {:10} {:10} {:10}'.format('Room#','Cost','Rooms','Bathrooms')
print(header)
if int(feeInput)>= htl_1.fee and int(roomInput)<= htl_1.rooms and int(bathInput)<= htl_1.bath:
print(htl_1.gethtl())
if int(feeInput)>= htl_2.fee and int(roomInput)<= htl_2.rooms and int(bathInput)<= htl_2.bath:
print(htl_2.gethtl())
if int(feeInput)>= htl_3.fee and int(roomInput)<= htl_3.rooms and int(bathInput)<= htl_3.bath:
print(htl_3.gethtl())
if int(feeInput)>= htl_4.fee and int(roomInput)<= htl_4.rooms and int(bathInput)<= htl_4.bath:
print(htl_4.gethtl())
if int(feeInput)>= htl_5.fee and int(roomInput)<= htl_5.rooms and int(bathInput)<= htl_5.bath:
print(htl_5.gethtl())
else:
print('Sorry, no rooms available that meet that criteria')
Without knowing the Hotels module I believe this syntax is correct. In order for the else to only activate when none of those if statements are true, you need to change them to elif (after the first if statement) as shown. The .format you used only works inside of a print statment as shown. Thanks
import Hotels
htl_1= Hotels.Hotels(111,100,1,1)
htl_2= Hotels.Hotels(112,200,2,1)
htl_3= Hotels.Hotels(113,250,2,2)
htl_4= Hotels.Hotels(114,300,3,2)
htl_5= Hotels.Hotels(115,350,3,3)
feeInput = int(input('Enter maximum per night fee: '))
roomInput = int(input('Enter minimum number of bedrooms: '))
bathInput = int(input('Enter minimum number of baths: '))
header = True
if feeInput >= htl_1.fee and roomInput <= htl_1.rooms and bathInput<= htl_1.bath:
print(htl_1.gethtl())
elif feeInput >= htl_2.fee and roomInput <= htl_2.rooms and bathInput <= htl_2.bath:
print(htl_2.gethtl())
elif feeInput >= htl_3.fee and roomInput <= htl_3.rooms and bathInput <= htl_3.bath:
print(htl_3.gethtl())
elif feeInput >= htl_4.fee and roomInput <= htl_4.rooms and bathInput <= htl_4.bath:
print(htl_4.gethtl())
elif feeInput >= htl_5.fee and roomInput <= htl_5.rooms and bathInput <= htl_5.bath:
print(htl_5.gethtl())
else:
print('Sorry, no rooms available that meet that criteria')
header = False
if header == True:
print('{0} {1} {2} {3}'.format(RoomVar,CostVar,RoomsVar,BathroomsVar))
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments