-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
130 lines (123 loc) · 2.15 KB
/
main.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
119
120
121
122
123
124
125
126
127
128
129
130
import os
import time
import sys
clear = lambda: os.system('cls') #on Windows System
sentence = input("Choose your sentence or word: ").lower()
clear()
l = []
total_guesses = []
c = 0 #max chances is 6
game_over = 6
counter = 0
count = 6
hangman_pics = ['''
+---+
| |
|
|
|
|
=========''', '''
+---+
| |
O |
|
|
|
=========''', '''
+---+
| |
O |
| |
|
|
=========''', '''
+---+
| |
O |
/| |
|
|
=========''', '''
+---+
| |
O |
/|\ |
|
|
=========''', '''
+---+
| |
O |
/|\ |
/ |
|
=========''', '''
+---+
| |
O |
/|\ |
/ \ |
|
=========''']
def drawing():
for i in range(0,7):
if i == c:
print (hangman_pics[i])
def main_section(x):
if guess == sentence:
clear()
print("guesses: " + " ".join(total_guesses))
drawing()
print(sentence)
time.sleep(2)
print("You win!")
sys.exit()
for i in sentence:
if guess == i and i not in l:
l.append(guess)
return x
break
if guess in total_guesses:
print("You already guessed this number!")
time.sleep(1)
return x
x = x + 1
return x
def after():
a = []
for i in sentence:
if i in l:
a.append(i)
elif i == " ":
a.append(i + " ")
else:
a.append("_ ")
print("".join(a))
def check_if_win():
x = sentence.replace(" ", "")
for i in l:
if i in sentence:
x = x.replace(i,"")
if x == "":
clear()
print("guesses: " + " ".join(total_guesses))
drawing()
after()
time.sleep(2)
print ("You win!")
sys.exit()
while c < game_over:
print("guesses: " + " ".join(total_guesses))
drawing()
after()
guess = input("Guess a character: ").lower()
c = main_section(c)
if guess not in total_guesses:
total_guesses.append(guess)
check_if_win()
clear()
print (hangman_pics[6])
print ("the phrase was: " + sentence)
time.sleep(2)
print ("Game Over!")