Skip to content

Commit edb0590

Browse files
committed
added all images and screenshots to Images folder
1 parent c6e9c40 commit edb0590

11 files changed

+164
-0
lines changed

Diff for: PyGamesScripts/Hangman/Images/categories.PNG

18.9 KB
Loading

Diff for: PyGamesScripts/Hangman/Images/guessing1.PNG

21.1 KB
Loading

Diff for: PyGamesScripts/Hangman/Images/guessing2.PNG

21.7 KB
Loading

Diff for: PyGamesScripts/Hangman/Images/guessing3.PNG

32.1 KB
Loading

Diff for: PyGamesScripts/Hangman/Images/guessing4.PNG

23.7 KB
Loading

Diff for: PyGamesScripts/Hangman/Images/hangman.PNG

10.5 KB
Loading

Diff for: PyGamesScripts/Hangman/Images/loosing.PNG

38.5 KB
Loading

Diff for: PyGamesScripts/Hangman/Images/playingAgain.PNG

21.2 KB
Loading

Diff for: PyGamesScripts/Hangman/Images/winning.PNG

17.3 KB
Loading

Diff for: PyGamesScripts/Hangman/README.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Hangman
2+
Hangman is a game developed in python rogramming Language using random module and some user nputs.
3+
4+
## About the game
5+
* It is a single player word guessing game.
6+
* The user can keep guessing the letters till they find the word or they have no chances left.
7+
8+
## How to play?
9+
* The user has to select a category
10+
* Then the user has to guess a letter
11+
* If he guessed a letter that is a part of the word he can guess another letter without loosing a chance
12+
* If he guessed a letter that is not a part of the word then he looses a chance.
13+
* The user can keep guessing letters till the word is found or the user has lost all his chances
14+
* The user can play this game any number of time he wishes to play
15+
16+
## Setup instructions
17+
1. Install Python 3.x (recommended) from https://www.python.org/downloads/
18+
2. Download this repository as zip and extract.
19+
3. Use Python IDLE
20+
4. Run the code and start playing.
21+
5. Have fun!!
22+
23+
## Output
24+
![GitHub Logo](images/hangman.png)
25+
26+
27+
## Author
28+
K.Harshitha

Diff for: PyGamesScripts/Hangman/hangman.py

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import random
2+
name = input("Enter your name ")
3+
print("Welcome ",name)
4+
again = "yes"
5+
#words in each category
6+
fruits =["apple","pineapple","orange","mango","banana","cherry"]
7+
countries =["india", "australia","england","germany","austria","indonesia","japan","singapore"]
8+
superheroes = ["batman","batwoman","catwoman","hawkeye","supergirl","thor","flash"]
9+
vegetables = ["tomato","potato","brinjal","onion","mushroom"]
10+
#various stages
11+
stages = [
12+
"""
13+
\t--------
14+
\t|
15+
\t|
16+
\t|
17+
\t|""",
18+
"""
19+
\t--------
20+
\t| |
21+
\t|
22+
\t|
23+
\t|""",
24+
"""
25+
\t--------
26+
\t| |
27+
\t| O
28+
\t|
29+
\t|""",
30+
"""
31+
\t--------
32+
\t| |
33+
\t| O
34+
\t| /
35+
\t|""",
36+
37+
"""
38+
\t--------
39+
\t| |
40+
\t| O
41+
\t| /|
42+
\t|""",
43+
44+
"""
45+
\t--------
46+
\t| |
47+
\t| O
48+
\t| /|\\
49+
\t|""",
50+
51+
"""
52+
\t--------
53+
\t| |
54+
\t| O
55+
\t| /|\\
56+
\t| /""",
57+
58+
"""
59+
\t--------
60+
\t| |
61+
\t| O
62+
\t| /|\\
63+
\t| / \\ """,
64+
65+
]
66+
67+
68+
while(again == "yes"):
69+
z=-1
70+
print("Lets play hangman ")
71+
#choosing a category
72+
print("\n\t\tCATEGORIES\n1.Fruits\n2.Countries\n3.Superheroes\n4.vegetables\n")
73+
n = int(input("Enter the category u want "))
74+
#chosing a rondom word from the choosen category
75+
if(n ==1):
76+
word = random.choice(fruits)
77+
elif(n ==2):
78+
word = random.choice(countries)
79+
elif(n==3):
80+
word = random.choice(superheroes)
81+
elif(n==4):
82+
word = random.choice(vegetables)
83+
#printing the word with blank spaces so that user can know the number of letters
84+
for i in word:
85+
print("_",end=" ")
86+
# having guess for storing all the right guesses alone and all_guess for storing all guesses from user
87+
guess =" "
88+
all_guess =" "
89+
#getting a letter from user
90+
ch = input("\n\nEnter the guessed character ");
91+
#int n = len(word)
92+
chance = 8
93+
while (chance>0):
94+
#wrong is a varibale used to check if word is fully found or not
95+
wrong = 0
96+
#printing the word with all right guesses made by the user
97+
for i in word:
98+
if (i == ch or i in guess):
99+
print(i,end=" ")
100+
else:
101+
print("_",end=" ")
102+
wrong+=1
103+
#checking if the word is fully found
104+
if( wrong == 0):
105+
print("\n\nCONGRATULATIONS!! YOU WIN !!! YOU FOUND THE WORD")
106+
break
107+
#checking if the letter is in the word and user has guessed that letter for the 1st time
108+
if(ch in word and ch not in guess):
109+
print("\nGood attempt ",ch," is in the word ")
110+
guess +=ch
111+
#showing the hangamn image if the user had made even 1 wrong guess before
112+
if(z>=0):
113+
print (stages[z])
114+
#checking if the letter is already guessed
115+
elif (ch in all_guess):
116+
print("\nYou have already guessed ",ch )
117+
#checking if it is a wrong guess and incrementing the hangman image to next stage and decrementing the chances
118+
elif (ch not in word):
119+
print("\n",ch," not in the given word try again ")
120+
z+=1
121+
print(stages[z])
122+
chance-=1
123+
print("\nYou still have ",chance," chances ")
124+
#loosing condition
125+
if( chance <1):
126+
print("\n\nSorry. YOU LOOSE!!!")
127+
print("The Word is ", word)
128+
break
129+
all_guess +=ch
130+
#getting the guessed cahr from user
131+
ch = input("\n\nEnter the guessed character ");
132+
#checking if user wants to play again
133+
again = input("Do you want to play again ")
134+
135+
136+

0 commit comments

Comments
 (0)