samedi 29 avril 2017

If Statement Firing Regardless of Conditions, Variable not Aggregating Past One

Please see my comments. They explain my problems. I have an if statement that is firing no matter what and a variable that is not aggregating properly and I don't know why. Thanks in advance. (The following is a hangman program currently in development. printBody() will eventually print out the whole man.)

import random

words = []

lettersGuessed = []

isGuessed = 0



wordFile = open(r'C:\Users\Sarah\PycharmProjects\hangman\words.txt')

for word in wordFile:
    words.append(word.strip())

limbCount = 0

def printBody(limbCount):
    limbCount += 1

    if limbCount == 1:
        print("\n0")
    elif limbCount == 2:
        print("\n0")
        print("\n |")

    return limbCount

mysteryWord = random.choice(words)

while len(mysteryWord) <= 1:
    mysteryWord = random.choice(words)

for letter in mysteryWord:
    print("?", end = "")
print("\n")

def isWon(mysteryWord, lettersGuessed):
    #win conditions
    count = 0
    for letter in mysteryWord:
        if letter in lettersGuessed:
            count += 1

        if count == len(mysteryWord):
            isGuessed = 1
            return isGuessed



count = 0
victory = 0
while not victory:



    guess = input("Guess a letter \n")

    if guess.upper() or guess.lower() in mysteryWord:
        lettersGuessed.append(guess)
        for letter in mysteryWord:
            if letter in lettersGuessed:
                print(letter, end ='')
            else:

                print("?", end = '')

    #this statement is firing no matter what and I don't know why
    if guess.upper() or guess.lower() not in mysteryWord:
        #when I call printBody() limbCount increases to one but then stays there. It won't go up to two or three.
        printBody(limbCount)



    print("\n")
    count = 0
    victory = isWon(mysteryWord, lettersGuessed)


print("Congratulations, you correctly guessed ", mysteryWord)

Aucun commentaire:

Enregistrer un commentaire