Oct-05-2019, 09:03 AM
So I'm trying to make hangman but the lives lost never go past 1, here's my code:
import random livesLost = 0 words=["forrest","donkey","pineapple","chicken","cat","elephant","zebra","headphones","book","trees","minecraft","spiderman","window","house","batman","car","computer","jazz","japan","fortnite","blue","purple","alphabet","money","highlighter","speaker","hangman","globe","earth","river","moustache","test","table","pancakes","chocolate","superman","keyboard"] def wordChoice(words): word=random.choice(words) return(word) def maskGen(myWord): lengthOfWord=len(myWord) x = 0 mask = "" while x < lengthOfWord: mask = mask + "_" x = x +1 return(mask) def guess(myWord,wordMask,lengthOfWord,livesLost): guess=input("Guess a letter: ") correct = False for i in range(lengthOfWord): if myWord[i] == guess: wordMask = wordMask[:i] + guess + wordMask[i+1:] correct = True if not correct: livesLost = livesLost + 1 print("Life Lost") print(livesLost) return livesLost print(wordMask) return wordMask def wordComplete(wordMask,myWord,lengthOfWord): for i in range(lengthOfWord): if wordMask[i]=="_": return False return True print("You have 9 lives total, just like a cat, until the man is hung") myWord=wordChoice(words) lengthOfWord=len(myWord) wordMask= maskGen(myWord) print(wordMask) wordFinished = False print(myWord) while wordFinished == False: wordFinished = wordComplete(wordMask,myWord,lengthOfWord) wordMask = guess(myWord,wordMask,lengthOfWord,livesLost) livesLost = guess(myWord,wordMask,lengthOfWord,livesLost) print("You have guessed the word, well done!") print("You lost",livesLost,"lives")