#
#hangman.py
#
import random
import sys
wlist = ['apple', 'blue', 'house', 'frog']
guessed = []
gright = []
choice = None
word = random.choice(wlist)
guesses = 0
# add dictionary for category
def menu():
while True:
print 'Welcome to hangman!'
print 'To start a new game type "n"\n'
print 'To quit the game press "q"\n'
choice = raw_input('enter your choice: ')
if choice == 'q':
break
if choice == 'n':
return choice
else:
print 'invalid selection'
continue
def length(n):
if len(n) > 1:
return False
else:
return True
def chckguess():
guesses = 0
n = raw_input('guess a letter: ')
if n == 'q':
sys.exit()
else:
if n in word:
if length(n) is True:
gright.append(n)
print 'correct!\n you have found the letters: %s' %gright
print 'you have used up %d of 5 wrong guesses so far' % guesses
return gright
else:
guesses += 1
print 'sorry that letter is not in the word'
return guesses
menu()
while True:
print 'your word is %d letters long' % len(word)
while guesses != 5:
chckguess()
if len(gright) == len(word):
print 'you win!' # later make user solve word
sys.exit()
else:
continue
The problem i'm having is that the guesses don't go higher (after 5 wrong guesses the player should lose)
Can anyone help? or give any other comments about the code?