为什么我的if语句正确时不被调用?

时间:2019-04-01 15:06:25

标签: python

我正在创建一个hang子手游戏,当我运行程序时,即使语句正确也不会调用if语句。我已将.lower更改为.lower(),但if语句仍未运行。

theWord = list(possibleWords[0])
theWord = (' ').join(theWord)

#graphics
```````````````````````````````````````
def graphics():
    graphic = []
    graphic.extend(theWord)

    for i in range(len(theWord)):
        graphic[i] = ("_")

    graphic = (' ').join(graphic)
    print (graphic)
`````````````````````````````````````````````
#input

````````````````````````````````````````````````````````````````````````
def inputs():
    count = (0)
    while len(theWord) > (count):
        for i in range(len(theWord)):
            print (count)
            guess = input("Guess a letter:").lower()
`````````````````````````````````````````````````````````````````````````
#right or wrong
```````````````````````````````````````````````````````````````````````````
            if (guess) == theWord[i]:
                graphic[i] = (guess)
                print (graphic)
                count = count + (1) 

inputs()

1 个答案:

答案 0 :(得分:2)

guess更改为input("Guess a letter:").lower()。没有约束的lower是一个函数,将导致对字符串的等效性检查失败:

somestr = 'HI'.lower

somestr
<built-in method lower of str object at 0x10e662f80>

somestr=='hi'
False

somestr = 'HI'.lower()

somestr=='hi'
True