为什么这会继续进入elif区块?

时间:2016-07-18 13:54:16

标签: python python-2.7 if-statement logical-operators

如果donate_money = 0并且spend_money是20,那么它应该检查第一个if语句并转到black_room吗?

def white_room():
    spend_money = raw_input("How much money have you spent?")
    donate_money = raw_input("How much money have you donated?")

    if (donate_money <= 0 and spend_money > 10): 
        print "You go to the black room!!"
        black_room()
    elif (donate_money > 0 and spend_money > 10):
        print donate_money
        print spend_money
        print "You can stay here..."
        white_room()
    else:
        print "You can live in the silver room forever"

1 个答案:

答案 0 :(得分:0)

raw_input更改为input,有关详细信息,请参阅How can I read inputs as integers?

spend_money = input("How much money have you spent?")
donate_money = input("How much money have you donated?")