简体   繁体   中英

Why isn't my if statement being called when it is correct?

I am creating a hangman game and when I run my program the if statement doesn't get called even if it is correct. I have changed my .lower to .lower() but the if statement is still not ran.

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()

Change guess to input("Guess a letter:").lower() . lower with no parens is a function and will fail the equivalency check to a string:

somestr = 'HI'.lower

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

somestr=='hi'
False

somestr = 'HI'.lower()

somestr=='hi'
True

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM