Lesson 15: Hangman v1

posted Mar 27, 2019, 8:05 AM by Attila Lengyel
word = input("Give me the hidden word:")

correctletters = ""
incorrectletters = ""

def drawhangman(word, correctletters, incorrectletters):
output = ""
for c in word:
if c in correctletters:
output += c + " "
else:
output += "_ "
print(output)

#drawhangman("rule", "eul", "")
#drawhangman("rule", "ul", "")
#drawhangman("rule", "l", "")
#drawhangman("rule", "", "")
#drawhangman("rule", "erul", "")

while len(word) != len(correctletters) and len(incorrectletters) < 8:
guess = input("Guess a letter:")
if guess in word and guess not in correctletters:
correctletters += guess
elif guess not in incorrectletters:
incorrectletters += guess
drawhangman(word, correctletters, incorrectletters)
Comments