-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHangman.py
118 lines (99 loc) · 2.64 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import random
print("Hangam")
print("---------------\n")
word_dictionary = [
"sunflower",
"apple",
"Kitchenette",
"Law",
"Invest",
"Jackpot",
"Ship",
"Significance",
"Campus",
"Carsick",
]
random_word = random.choice(word_dictionary)
for i in random_word:
print("_", end=" ")
def print_hangman(wrong):
if wrong == 0:
print("\n+---+")
print(" |")
print(" |")
print(" |")
print(" ===")
elif wrong == 1:
print("\n+---+")
print("O |")
print(" |")
print(" |")
print(" ===")
elif wrong == 2:
print("\n+---+")
print("O |")
print("| |")
print(" |")
print(" ===")
elif wrong == 3:
print("\n+---+")
print(" O |")
print("/| |")
print(" |")
print(" ===")
elif wrong == 4:
print("\n+---+")
print(" O |")
print("/|\ |")
print(" |")
print(" ===")
elif wrong == 5:
print("\n+---+")
print(" O |")
print("/|\ |")
print("/ |")
print(" ===")
elif wrong == 6:
print("\n+---+")
print(" O |")
print("/|\ |")
print("/ \ |")
print(" ===")
def print_word(guessedletters):
count = 0
rightletters = 0
for char in random_word:
if char in guessedletters:
print(random_word[count], end=" ")
rightletters += 1
else:
print(" ", end=" ")
count += 1
return rightletters
def printLines():
print("\r")
for char in random_word:
print("\u203E", end=" ")
length_of_word_to_guess = len(random_word)
amount_of_times_wrong = 0
current_guess_index = 0
current_letters_guessed = []
current_letters_right = 0
while amount_of_times_wrong != 6 and current_letters_right != length_of_word_to_guess:
print("\nWord you guessed before: ")
for letter in current_letters_guessed:
print(letter, end=" \n")
letterGuessed = input("\n=>Please guess new letter: ")
if random_word[current_guess_index] == letterGuessed:
print_hangman(amount_of_times_wrong)
current_guess_index += 1
current_letters_guessed.append(letterGuessed)
current_letters_right = print_word(current_letters_guessed)
printLines()
else:
amount_of_times_wrong += 1
current_letters_guessed.append(letterGuessed)
print_hangman(amount_of_times_wrong)
current_letters_right = print_word(current_letters_guessed)
printLines()
print("Game is over... Thank you for playing :)")