-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhangman.py
More file actions
27 lines (27 loc) · 1.15 KB
/
hangman.py
File metadata and controls
27 lines (27 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def hangman(secretWord):
print 'Welcome to the game, Hangman!', '\nI am thinking of a word that is ' + str(len(secretWord)) + ' letters long.'
lettersGuessed = []
win = False
miss = 8
while True:
print '-------------'
if miss == 0:
print 'Sorry, you ran out of guesses. The word was ' + secretWord + '.'
break;
win = isWordGuessed(secretWord, lettersGuessed)
if win == True:
print 'Congratulations, you won!'
break;
print 'You have ' + str(miss) + ' guesses left.', '\nAvailable letters: ' + getAvailableLetters(lettersGuessed)
guess = raw_input('Please guess a letter: ').lower()
if guess in lettersGuessed:
print 'Oops! You\'ve already guessed that letter: ', getGuessedWord(secretWord, lettersGuessed)
else:
lettersGuessed.append(guess)
lettersGuessed.sort()
if guess not in secretWord:
print 'Oops! That letter is not in my word: ',
miss -= 1
else:
print 'Good guess: ',
print getGuessedWord(secretWord, lettersGuessed)