1
2#importing the time module
3import time
4
5#welcoming the user
6name = raw_input("What is your name? ")
7
8print "Hello, " + name, "Time to play hangman!"
9
10print "
11"
12
13#wait for 1 second
14time.sleep(1)
15
16print "Start guessing..."
17time.sleep(0.5)
18
19#here we set the secret
20word = "secret"
21
22#creates an variable with an empty value
23guesses = ''
24
25#determine the number of turns
26turns = 10
27
28# Create a while loop
29
30#check if the turns are more than zero
31while turns > 0:
32
33 # make a counter that starts with zero
34 failed = 0
35
36 # for every character in secret_word
37 for char in word:
38
39 # see if the character is in the players guess
40 if char in guesses:
41
42 # print then out the character
43 print char,
44
45 else:
46
47 # if not found, print a dash
48 print "_",
49
50 # and increase the failed counter with one
51 failed += 1
52
53 # if failed is equal to zero
54
55 # print You Won
56 if failed == 0:
57 print "
58You won"
59
60 # exit the script
61 break
62
63 print
64
65 # ask the user go guess a character
66 guess = raw_input("guess a character:")
67
68 # set the players guess to guesses
69 guesses += guess
70
71 # if the guess is not found in the secret word
72 if guess not in word:
73
74 # turns counter decreases with 1 (now 9)
75 turns -= 1
76
77 # print wrong
78 print "Wrong
79"
80
81 # how many turns are left
82 print "You have", + turns, 'more guesses'
83
84 # if the turns are equal to zero
85 if turns == 0:
86
87 # print "You Lose"
88 print "You Lose
89"
90