# Hangman
print ("Let's play Hangman!")
print( " O \n"+" | \n" +" \ / \n" + " | \n"+" /\ ")
category = input("Pick a Catergory: Animals, Places, People, Movies: ")
if category in ["Animals", "animals", "a", "A", "Animal", "animal","ANIMAL", "ANIMALS"]:
picks = ["bird", "dog", "cat", "fish", "snake"]
from random import choice
word = choice(picks)
print("Your word is " + str(len(word)) + " letters long")
alreadyGuessed = []
gameOver = False
while gameOver == False:
guess = input("What is your guess? ")
alreadyGuessed.append(guess)
if guess in list(word):
print ("Correct!...letters already guessed = " + str(alreadyGuessed))
elif guess == word:
print("Correct!...YOU WON!")
gameOver = True
else:
print("Wrong Stupid!")
The problem i am having is when the user is guessing one letter at a time. It saves the letters guessed into the list alreadyGuessed, however, i can't seem to get the program to print YOU Won! and exit the loop once all the letters in the word have been guessed.
i tried to nest the an if statement into the first if statement, for example:
if list(word) in alreadyGuessed:
print ("you Won")
gameOver = True
and many different variations of this but still can't find a solution. I'm still learning python so i apologize if i my coding is sloppy.

New Topic/Question
Reply



MultiQuote




|