I'm trying to learn programming with python by myself and I've made a hangman game for exercise purposes.
import random
words = ['egypt', 'automobile', 'world', 'python', 'miniority', 'treehouse', 'friend', 'program' , 'people']
def start():
print "Hello! Welcome to a tiny hangman game that I made for exercise purposes."
raw_input('Press enter to continue')
key = random.randint(0,(len(words)-1))
global word
word = words[key]
global word_template
word_template = '_' * len(word)
word_template = list(word_template)
guesser()
def draw(int):
if int == 0:
print " _________ "
print "| | "
print "| "
print "| "
print "| "
print "| "
print "| "
elif int == 1:
print " _________ "
print "| | "
print "| 0 "
print "| "
print "| "
print "| "
print "| "
elif int == 2:
print " _________ "
print "| | "
print "| 0 "
print "| | "
print "| "
print "| "
print "| "
elif int == 3:
print " _________ "
print "| | "
print "| 0 "
print "| /| "
print "| "
print "| "
print "| "
elif int == 4:
print " _________ "
print "| | "
print "| 0 "
print "| /|\\ "
print "| "
print "| "
print "| "
elif int == 5:
print " _________ "
print "| | "
print "| 0 "
print "| /|\\ "
print "| / "
print "| "
print "| "
elif int == 6:
print " _________ "
print "| | "
print "| 0 "
print "| /|\\ "
print "| / \\ "
print "| "
print "| "
def guesser():
global counter
counter = 0
checker = list(word)
guesses = []
while counter < 6:
draw(counter)
print word_template
print '\nYour previous letters are:', guesses
print 'You have ',(6 - counter), 'guesses left.'
choice = raw_input('Choose a letter: ')
if choice in guesses:
print "\nYou made that guess before!"
elif choice in checker:
if checker.count(choice) == 1:
pointer = checker.index(choice)
word_template[pointer] = checker[pointer]
checker[pointer] = 1
guesses.append(choice)
print "\nThat's a hit!"
if list(word) == word_template:
win()
else:
continue
elif checker.count(choice) > 1:
for i in range(0, checker.count(choice)):
pointer = checker.index(choice)
word_template[pointer] = checker[pointer]
checker[pointer] = 1
guesses.append(choice)
print "\nWOW! That was a multiple hit!"
if list(word) == word_template:
win()
else:
continue
elif choice not in checker:
guesses.append(choice)
counter += 1
print '\nMiss!'
if counter == 6:
draw(counter)
print 'Sorry, you lose :('
print 'The word was:', word
retry()
def win():
print "\nYou won!"
print "You found the word:", word
retry()
def retry():
print "Do you want to play again?"
choice = raw_input('Type retry for restart, Ctrl + C for exit:')
if choice == 'retry':
start()
else:
print "Sorry, I can't understand."
retry()
start()
Is there any flaws on my logic and what can you suggest me to improve my code?