-
Notifications
You must be signed in to change notification settings - Fork 0
/
hangman.py
34 lines (26 loc) · 1019 Bytes
/
hangman.py
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
import random as rand
life = 6
words = ["english", "fun", "run", "word", "games", "tryhard", "funny", "pain", "list", "coding", "math", "person", "table", "essay", "hangman", "writing", "firetruck"]
userguesses = []
word = rand.choice(words)
wordlist = list(word)
wordlen = len(word)
while life > 0:
display = ''.join(i if i in userguesses else "_" for i in word)
if display == word:
print(f"You won! The word was {word}!")
break
print(display)
guess = input("What letter do you guess? ").lower()
if guess in userguesses:
print("You already guessed this letter, try something else.")
elif guess in wordlist:
print (f"Yes, the letter {guess} is in the word!")
userguesses.append(guess)
elif guess not in wordlist:
print (f"No, the letter {guess} is not in the word!")
life = life - 1
print (f"You have {life} live(s) left.")
userguesses.append(guess)
if life == 0:
print (f"The word was: {word}")