Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e7d2a17

Browse files
Merge pull request avinashkranjan#796 from Yuvraj-kadale/hangman
Terminal Hangman
2 parents bb8220f + e002080 commit e7d2a17

File tree

3 files changed

+140
-0
lines changed

3 files changed

+140
-0
lines changed

‎Terminal Hangman/Readme.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Terminal Hangman
2+
3+
- Guess the Word in less than 10 attempts
4+
5+
![image](https://user-images.githubusercontent.com/43489758/113258092-1d354e00-92e9-11eb-9cdb-a4c99bd960ec.png)
6+
7+
- Guess it correctly and save the wise man.
8+
9+
![image](https://user-images.githubusercontent.com/43489758/113258225-4c4bbf80-92e9-11eb-935a-37546b8a8dfd.png)
10+
11+
- Save the last breadth less you loose
12+
13+
![image](https://user-images.githubusercontent.com/43489758/113258344-743b2300-92e9-11eb-983d-392e358b1f1e.png)
14+
15+
![image](https://user-images.githubusercontent.com/43489758/113258432-8fa62e00-92e9-11eb-979d-686ec3168332.png)
16+
17+
18+
> Made with ❤ , [Yuvraj kadale](https://github.com/Yuvraj-kadale) #Gssoc 2021

‎Terminal Hangman/T_hangman.py‎

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import random
2+
3+
def Mywordlist():
4+
'''
5+
This function will fetch random words from my custom word list by opening file in read mode
6+
'''
7+
with open("./Terminal Hangman/data.txt", "r") as file:
8+
alldata = file.read()
9+
words = list(map(str, alldata.split()))
10+
11+
return words
12+
13+
def hangman():
14+
'''
15+
This is the main fuction behind the logic.
16+
'''
17+
18+
word = random.choice(Mywordlist()) #Fetching Word list we would like to play with.
19+
turns = 10 #Total number of chance given to the user
20+
guessmade = ''
21+
22+
while len(word) > 0:
23+
main = ""
24+
missed = 0
25+
26+
for letter in word:
27+
if letter in guessmade:
28+
main = main + letter
29+
else:
30+
main = main + "_" + " "
31+
if main == word:
32+
print(main)
33+
print("You win!")
34+
break
35+
36+
print("Guess the word:", main)
37+
guess = input()
38+
validLetters = guess.isalpha()
39+
40+
if validLetters is True:
41+
guessmade = guessmade + guess
42+
else:
43+
print("Enter a valid single character")
44+
guess = input()
45+
46+
if guess not in word:
47+
turns = turns - 1
48+
if turns == 9:
49+
print("9 turns left")
50+
print(" -------- ")
51+
if turns == 8:
52+
print("8 turns left")
53+
print(" -------- ")
54+
print(" O ")
55+
if turns == 7:
56+
print("7 turns left")
57+
print(" -------- ")
58+
print(" O ")
59+
print(" | ")
60+
if turns == 6:
61+
print("6 turns left")
62+
print(" -------- ")
63+
print(" O ")
64+
print(" | ")
65+
print(" / ")
66+
if turns == 5:
67+
print("5 turns left")
68+
print(" -------- ")
69+
print(" O ")
70+
print(" | ")
71+
print(" / \ ")
72+
if turns == 4:
73+
print("4 turns left")
74+
print(" -------- ")
75+
print(" \ O ")
76+
print(" | ")
77+
print(" / \ ")
78+
if turns == 3:
79+
print("3 turns left")
80+
print(" -------- ")
81+
print(" \ O / ")
82+
print(" | ")
83+
print(" / \ ")
84+
if turns == 2:
85+
print("2 turns left")
86+
print(" -------- ")
87+
print(" \ O /| ")
88+
print(" | ")
89+
print(" / \ ")
90+
if turns == 1:
91+
print("1 turns left")
92+
print("Last breaths counting, Take care!")
93+
print(" -------- ")
94+
print(" \ O_|/ ")
95+
print(" | ")
96+
print(" / \ ")
97+
if turns == 0:
98+
print("You loose")
99+
print("You let a kind man die")
100+
print(" -------- ")
101+
print(" O_| ")
102+
print(" /|\ ")
103+
print(" / \ ")
104+
break
105+
106+
107+
name = input("Enter your name: ")
108+
print("Welcome", name)
109+
print("-------------------")
110+
print("try to guess the word in less than 10 attempts")
111+
hangman()
112+
print()

‎Terminal Hangman/data.txt‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
python
2+
spiderman
3+
tiger
4+
superman
5+
thor
6+
pokemon
7+
avengers
8+
savewater
9+
earth
10+
annable

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /