Web Analytics

So I do Computer Science and I am trying to add a function that counts how many wrong guesses the user does and draws a hangman. How can I do this? Thanks...


NB: Please make sure it is correct before replying to me.

The code is below...



import random


word = ['ceraunophilia','clinomania','nyctophilia','pluviophile','nyctophile','palinoia','ceraunophile','catharsis','rhinotillexomania','numinous']

word = random.choice(word)


def setup_word():

guessed = ["_"]*len(word)

print('Guess the word: ')

return guessed




def guess(letter, guessed):

wrong = 0

for i in range(len(word)):

if word[i] == letter:

guessed[i]=letter

found=True

if word[i] != letter:

wrong+=1


printguess(guessed)

return guessed



def printguess(guessed):

printguess=""

for i in guessed:

printguess+=i+" "

print(printguess)


def play(guessed):

if("".join(guessed) == word):

print('You win')

else:

play(guess(input('enter letter to guess'), guessed))


play(setup_word())