mardi 9 juin 2020

First condition of an if-block is getting skipped

I'm writing code with Python 2.7 that checks if a character is present in a input string but Python keeps skipping part of my if-statement.

Each time I run the code and enter a guess character value, the execution goes straight to the else statement and never executes the if(guess in PuzzleSetter) == True block at all.

What am I doing wrong?

while(True):
    guess = raw_input("\nGuessing player make your guess: ")
    if len(guess) != 1:
        print("You are meant to enter a single letter")
        continue
    else:
        guess = guess.upper()
        print(guess)
        if(guess in PuzzleSetter) == True:
            finder = PuzzleSetter.find(guess)
            print(PuzzleSetter+" contains "+str(PuzzleSetter.count(guess))+" "+guess+"'s")
            for count in range(PuzzleSetter.count(guess)):
                List[finder] = guess.upper()
                finder = PuzzleSetter.find(guess, finder+1)
            print(List)
            if List.count("__") == 0:
                print("Guessing player wins!")
                break
        else:
            HangerMan()
            enter += 1
            if enter == 7:
                print("Guessing player lost!")
                print("\nPlayer two becomes the puzzle setter")
                setPuzzle()

Aucun commentaire:

Enregistrer un commentaire