Skip to content

Commit 539785d

Browse files
feat python proyect hangmen
python proyect hangmen resolve: see also:
1 parent ecf918a commit 539785d

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

Proyect Game hangmen/hangmen.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import random
2+
def hangman():
3+
4+
word = random.choice(["pugger" , "littlepugger" , "tiger" , "superman" , "thor" , "pokemon" , "avengers" , "savewater" , "earth" , "annable" ])
5+
validLetters = 'abcdefghijklmnopqrstuvwxyz'
6+
turns = 10
7+
guessmade = ''
8+
9+
while len(word) > 0:
10+
main = ""
11+
missed = 0
12+
13+
for letter in word:
14+
if letter in guessmade:
15+
main = main + letter
16+
else:
17+
main = main + "_" + " "
18+
if main == word:
19+
print(main)
20+
print("You win!")
21+
break
22+
23+
print("Guess the word:" , main)
24+
guess = input()
25+
26+
if guess in validLetters:
27+
guessmade = guessmade + guess
28+
else:
29+
print("Enter a valid character")
30+
guess = input()
31+
32+
if guess not in word:
33+
turns = turns - 1
34+
if turns == 9:
35+
print("9 turns left")
36+
print(" -------- ")
37+
if turns == 8:
38+
print("8 turns left")
39+
print(" -------- ")
40+
print(" O ")
41+
if turns == 7:
42+
print("7 turns left")
43+
print(" -------- ")
44+
print(" O ")
45+
print(" | ")
46+
if turns == 6:
47+
print("6 turns left")
48+
print(" -------- ")
49+
print(" O ")
50+
print(" | ")
51+
print(" / ")
52+
if turns == 5:
53+
print("5 turns left")
54+
print(" -------- ")
55+
print(" O ")
56+
print(" | ")
57+
print(" / \ ")
58+
if turns == 4:
59+
print("4 turns left")
60+
print(" -------- ")
61+
print(" \ O ")
62+
print(" | ")
63+
print(" / \ ")
64+
if turns == 3:
65+
print("3 turns left")
66+
print(" -------- ")
67+
print(" \ O / ")
68+
print(" | ")
69+
print(" / \ ")
70+
if turns == 2:
71+
print("2 turns left")
72+
print(" -------- ")
73+
print(" \ O /| ")
74+
print(" | ")
75+
print(" / \ ")
76+
if turns == 1:
77+
print("1 turns left")
78+
print("Last breaths counting, Take care!")
79+
print(" -------- ")
80+
print(" \ O_|/ ")
81+
print(" | ")
82+
print(" / \ ")
83+
if turns == 0:
84+
print("You loose")
85+
print("You let a kind man die")
86+
print(" -------- ")
87+
print(" O_| ")
88+
print(" /|\ ")
89+
print(" / \ ")
90+
break
91+
92+
93+
name = input("Enter your name")
94+
print("Welcome" , name )
95+
print("-------------------")
96+
print("try to guess the word in less than 10 attempts")
97+
hangman()
98+
print()

0 commit comments

Comments
 (0)