-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhangman.py
53 lines (48 loc) · 1.85 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import random
# import string
from words import wordlist
def choice():
return random.choice(wordlist)
# print(choice())
def printlives(l):
print(f"you now have {l} lives left!!!!!!")
if __name__ == '__main__':
# print(choice())
chosenword = choice()
print(chosenword)
lives = len(chosenword)
print(f"The chosen Word is {lives} letters long, so you will have only {lives} turns only.....Good Luck!!!!!!\n\n")
userword = "-"*lives
print("the initial word is : ",userword)
usedletters = []
while userword != chosenword and lives > 0:
userinput = input("Please input a letter : ")
# if len(userinput) > 1:
# print("Please input correctly")
# lives -= 1
# printlives(lives)
# continue
if userinput in usedletters or userinput not in chosenword:
print("This letter is not in word or has been already used.Please choose another......")
lives -= 1
printlives(lives)
else:
# userword = userword.replace("-",userinput,chosenword.count(userinput))
# i = 0
for i in range(0,len(chosenword)):
if chosenword[i] == userinput:
userword = userword[:i] + userinput + userword[i+1:]
# print(userword,"jhedvbsafcjhsbvedfrj")
else:
pass
# i = 0
if userword == chosenword:
print("Congratulations!!!!!!!!!!!!!")
print("You have succesfully guessed the word " + chosenword)
break
print(userword)
usedletters.append(userinput)
print("The used letters are : ",end=" ")
print(" ".join(usedletters))
# lives -= 1
# printlives(lives)