-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
61 lines (44 loc) · 1.82 KB
/
main.py
File metadata and controls
61 lines (44 loc) · 1.82 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import random
import string
from words import words
from hangman import hangman
print("Hey!!!!!!! \n\n\t*******\nWelcome to HangmanPy\n\t*******\n\nPlease enter your name \n\t")
name = input()
print("Woah! \n Let's begin the game " + name, "\n\n")
def get_word(words):
word = random.choice(words)
while '-' in word or ' ' in word:
word = random.choice(words)
return word.upper()
def hangmanpy():
word = get_word(words)
letters_in_word = set(word)
alphabet = set(string.ascii_uppercase)
used_letters = set()
life = 10
while len(letters_in_word) > 0 and life > 0:
print(name, '!!!!!\n', life, 'lives left and you have used these letters: ', ' '.join(used_letters))
word_list = [letter if letter in used_letters else '-' for letter in word]
print(hangman[life])
print('\t\tCurrent word: ', ' '.join(word_list))
using_letter = input('\t\tGuess a letter: ').upper()
if using_letter in alphabet - used_letters:
used_letters.add(using_letter)
if using_letter in letters_in_word:
letters_in_word.remove(using_letter)
print('')
else:
life = life - 1
print('\nYour letter,', using_letter, 'is not in the word.')
elif using_letter in used_letters:
print('\n', name, '!!!\t''you have already used that letter. Guess another letter.')
else:
print('\nThat is not a valid letter.')
if life == 0:
print(hangman[life])
print('You lost. The word was', word)
else:
print('\t************************\n\tYAY! \n\tYou guessed the word\n\t\t', word,
'\n''\t************************\n')
if __name__ == '__main__':
hangmanpy()