我的代码有几个问题需要帮助解决
代码:
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')
您需要将
if
更改为elif
,并将头打印代码移动到if
块在不了解Hotels模块的情况下,我相信这个语法是正确的。为了使else只在那些if语句都不为true时激活,您需要将它们更改为elif(在第一个if语句之后),如图所示。您使用的.format只在打印语句中起作用,如图所示。谢谢
相关问题 更多 >
编程相关推荐