Skip to content

Commit e034cf2

Browse files
authored
Merge pull request Shahrayar123#78 from TheStrangerDoctor/newbranch
"added games in readme"
2 parents 687c883 + dc66ae2 commit e034cf2

3 files changed

Lines changed: 85 additions & 32 deletions

File tree

Hangman Game/added.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
I added extra features

Hangman Game/hangman.py

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,70 @@
1+
# IMPORT ALL LIBRARIES
2+
import requests
13
import random
4+
from lxml import etree
5+
6+
alphabetChoice = random.choice(["a","b","c","d","e","f","g","h","i"])
7+
columnChoice = random.choice(range(1, 3))
8+
wordChoice = random.choice(range(1, 10))
9+
10+
def checkName(name):
11+
if name == "":
12+
print("Sorry, you did not enter your name")
13+
return 0
14+
else:
15+
print("\n--------------------------------------\n")
16+
return 1
217

318
def hangman():
4-
WORD = random.choice(["pencil","pen","superman","glasses","mobile","calculator","laptop","book","person","animal"])
19+
# Define the URL and XPath
20+
url = f"https://randomword.com/words/{alphabetChoice}.html"
21+
xpath = f"/html/body/div[1]/div[2]/div/div/div[1]/div[2]/ul[1]/li[{wordChoice}]"
22+
23+
# Send a GET request to the website
24+
response = requests.get(url)
25+
html_content = response.content
26+
27+
# Parse the HTML content
28+
tree = etree.HTML(html_content)
29+
30+
# Extract the desired element using the XPath
31+
word = tree.xpath(xpath)[0].text.strip()
532
# print(WORD)
633
alphabets = "abcdefghijklmnopqrstuvwxyz"
734
chance = 10
835
guess_made = ""
936

10-
while len(WORD) > 0:
37+
while len(word) > 0:
1138
main = ""
12-
for letter in WORD:
39+
for letter in word:
1340
if letter in guess_made:
1441
main += letter
1542
else:
1643
main = main +"_"+" "
1744

18-
if main == WORD:
45+
if main == word:
1946
print("Letter is: "+ main)
2047
print("You win! ")
2148
break
2249

23-
guess = input("Guess the word "+ main)
50+
print(f"Guess the word {main}")
51+
guess = input("\n")
2452

2553
if guess in alphabets:
2654
guess_made = guess_made + guess
2755
else:
28-
guess = input("Enter the valid character: ")
56+
guess = input("Enter the valid character:\n")
2957

30-
if guess not in WORD:
58+
if guess not in word:
59+
print(word)
3160
chance -= 1
3261

3362
if chance == 9:
3463
print("9 turns left")
3564
print("\n---------------------------- ")
3665

3766
if chance == 8:
38-
print("9 turns left")
67+
print("8 turns left")
3968
print("\n---------------------------- ")
4069
print(" O ")
4170
if chance == 7:
@@ -82,7 +111,7 @@ def hangman():
82111
print(" / \ ")
83112

84113
if chance == 0:
85-
print("You loss that man")
114+
print(f"You loss that man. The answer was {word}")
86115
print("Game Over")
87116
print(" O____| ")
88117
print(" /|\ ")
@@ -91,8 +120,10 @@ def hangman():
91120
break
92121

93122

94-
95123
name = input("Hey there! What is your name: ")
96-
print(name+" lets play a game")
97-
print("\n--------------------------------------\n")
98-
hangman()
124+
125+
if checkName(name):
126+
print(name+" lets play a game")
127+
hangman()
128+
else:
129+
pass

README.md

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,73 @@
33
A Hub of Python Projects for Begineers.
44

55

6+
7+
68
## Description
79

810
Welcome aboard fellow developer, this repository is intended for beginners who can use it for project building, open source contribution and get the most from it.
911
If you are new to open source then do consider this repository to start with.
1012

1113
There are various projects under this repository which will be helpful for you get familiar with Python programming.
1214

15+
16+
1317
## Projects
1418

1519
This repository has the following Projects.
1620
### Basic Projects along with *Miscellaneous Games* like-
17-
- Tic-Tac-Toe
18-
- Towers of Hanoi
19-
- Hangman game
20-
- Turtle crossing Capstone Game
21-
- SNAKE
22-
- Number Guessing Game
23-
- Rock Paper Scissors Game
24-
- Sudoku-Solver
21+
- [Tic-Tac-Toe](https://github.com/Shahrayar123/Python-Projects/tree/master/Tic-Tac-Toe)
22+
- [Towers of Hanoi](https://github.com/Shahrayar123/Python-Projects/tree/master/Towers%20of%20Hanoi)
23+
- [Hangman game](https://github.com/Shahrayar123/Python-Projects/tree/master/Hangman%20Game)
24+
- [Turtle crossing Capstone Game](https://github.com/Shahrayar123/Python-Projects/tree/master/Turtle%20Crossing%20Capstone%20Game)
25+
- [SNAKE](https://github.com/Shahrayar123/Python-Projects/tree/master/SNAKE)
26+
- [Number Guessing Game](https://github.com/Shahrayar123/Python-Projects/tree/master/Number%20Guessing%20Game)
27+
- [Rock Paper Scissors Game](https://github.com/Shahrayar123/Python-Projects/tree/master/Rock%20Paper%20Scissors%20Game)
28+
- [Sudoku-Solver](https://github.com/Shahrayar123/Python-Projects/tree/master/Sudoku-Solver)
2529

2630
### OpenCV projects.
2731

28-
- AI_Attendence_Program
29-
- FaceRecognition
30-
- QR Code generator
31-
32+
- [AI_Attendence_Program](https://github.com/Shahrayar123/Python-Projects/tree/master/AI_Attendence_Program)
33+
- [FaceRecognition](https://github.com/Shahrayar123/Python-Projects/tree/master/FaceRecgonition)
34+
- [QR Code generator](https://github.com/Shahrayar123/Python-Projects/tree/master/QR%20Code)
3235

36+
### Other projects (not yet validated).
37+
- [AirCanvas](https://github.com/Shahrayar123/Python-Projects/tree/master/AirCanvas)
38+
- [Conway's Game of Life](https://github.com/Shahrayar123/Python-Projects/tree/master/Conway's%20Game%20of%20Life)
39+
- [Dice-Simulator](https://github.com/Shahrayar123/Python-Projects/tree/master/Dice-Simulator)
40+
- [Dictionary-App](https://github.com/Shahrayar123/Python-Projects/tree/master/Dictionary-App)
41+
- [Riddle](https://github.com/Shahrayar123/Python-Projects/tree/master/Riddle)
42+
- [SchduledMessageWhatsApp](https://github.com/Shahrayar123/Python-Projects/tree/master/SchduledMessageWhatsApp)
43+
- [Screen_Recording_App](https://github.com/Shahrayar123/Python-Projects/tree/master/Screen_Recording_App)
44+
- [Student Management System](https://github.com/Shahrayar123/Python-Projects/tree/master/Student%20Management%20System)
45+
- [Web_Automation](https://github.com/Shahrayar123/Python-Projects/tree/master/Web_Automation)
46+
- [Youtube Searching Script](https://github.com/Shahrayar123/Python-Projects/tree/master/Youtube%20Searching%20Script)
47+
- [pokemone_battle](https://github.com/Shahrayar123/Python-Projects/tree/master/pokemone_battle.py)
3348

3449

3550
## Contribution
3651

3752
Contributions are always welcome!
53+
54+
55+
3856
### Instructions
39-
- Fork this repository
57+
1. Fork this repository
58+
59+
2. Clone your forked repository
60+
61+
3. Add your scripts
62+
63+
4. Commit and push
4064

41-
- Clone your forked repository
65+
5. Create a pull request
4266

43-
- Add your scripts
67+
6. Star this repository
4468

45-
- Commit and push
69+
7. Wait for pull request to merge
4670

47-
- Create a pull request
4871

49-
- Star this repository
5072

51-
- Wait for pull request to merge
5273

5374
#### Celebrate your first step into the open source world and contribute more.
5475

0 commit comments

Comments
 (0)