比较2个字符串问题

时间:2015-03-16 13:44:16

标签: python python-2.7

我的bloc elif有一个循环里面比较2个字符串(字母)但是即使我把正确的字母仍然运行循环..我一直在寻找通过论坛,尝试了很多东西,但它仍然运行循环我不知道为什么。

elif wallet > 0: # if player still wants to play (if wallet is not empty)
            restartp = raw_input('Keep playing [y/n] ? ')

            while restartp != 'y' or restartp != 'n':
                    print '[!] Wrong answer !'
                    restartp = raw_input('Keep playing [y/n] ? ')

            if restartp == 'y':
                    restart = 1

            elif restartp == 'n':
                    restart = 0
                    keep = False

1 个答案:

答案 0 :(得分:0)

restartp != 'y' or restartp != 'n'将始终为True。

您可以改为使用:

restartp != 'y' and restartp != 'n'

或者:

while restartp not in ('y', 'n'):