使用==和或在python中进行字符串比较

时间:2015-07-14 03:06:56

标签: python string python-3.x string-comparison comparison-operators

low = 0
high = 100
print "Please think of a number between 0 and 100!"
guess = 0
guess =high/2
print "Is your secret number: %d" % guess
while (guess <= 100 ):
    value = raw_input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly.")
if(value == 'h'):
     high = guess;
     guess =(low+guess)/2
     print "Is your secret number: %d" % guess 
elif(value == 'l'):
        low =  guess
        guess = (low + high)/2
        print "Is your secret number: %d" % guess 
elif(value == 'c' or "right" or "yes" or 'okay' or "correct"):
        print "Game over. Your secret number was: %d" %guess
        break
else:
    print "Sorry, I did not understand your input."

如果我输入了value =“right”,则在elif块中我希望代码能够检查整个单词。但在执行时它允许任何字母。有人可以帮我解决这个问题吗?

0 个答案:

没有答案