Skip to content

Commit 0a8911d

Browse files
Merge pull request #2314 from khushimarothi/gssoc
Number guess game
2 parents 1b8b7b2 + 0e9da34 commit 0a8911d

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

Number-Guess-Game/Readme.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Number Guessing Game
2+
3+
This is a simple number guessing game implemented in Python. The program generates a random number between 0 and the user-specified range and challenges the player to guess the correct number.
4+
5+
## Getting Started
6+
7+
To run the game, you'll need Python 3.x installed on your computer. If you don't have Python installed, you can download it from the official website: [Python.org](https://www.python.org/downloads/).
8+
9+
### How to Play
10+
11+
1. Clone or download this repository to your local machine.
12+
2. Open a terminal or command prompt and navigate to the project directory.
13+
3. Run the `number_guessing_game.py` script using the following command:
14+
15+
```bash
16+
python number_guessing_game.py
17+
```
18+
19+
4. The program will ask you to input a range (a positive integer greater than 0) to generate a random number.
20+
5. After specifying the range, the program will generate a random number.
21+
6. You need to make guesses to find the correct number.
22+
7. The program will provide hints if your guess is above or below the generated number.
23+
8. Keep guessing until you find the correct number.
24+
9. The game will display the number of guesses it took to find the correct number.
25+
26+
### Example Gameplay
27+
28+
```
29+
Type a number: 100
30+
Make a guess: 50
31+
You were below the number!
32+
Make a guess: 75
33+
You were below the number!
34+
Make a guess: 90
35+
You were above the number!
36+
Make a guess: 85
37+
You were below the number!
38+
Make a guess: 88
39+
You got it!
40+
You got it in 5 guesses
41+
```
42+
43+
Feel free to contribute or make suggestions for improvements. Happy coding!

Number-Guess-Game/numberguess.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import random
2+
3+
top_of_range = input("Type a number: ")
4+
5+
if top_of_range.isdigit():
6+
top_of_range = int(top_of_range)
7+
8+
if top_of_range <=0:
9+
print('Please type a number larger than 0 next time. ')
10+
quit()
11+
else:
12+
print('Please type a number next time. ')
13+
quit()
14+
15+
random_number = random.randint(0, top_of_range)
16+
guesses = 0
17+
18+
while True:
19+
guesses += 1
20+
user_guess = input('Make a guess: ')
21+
if user_guess.isdigit():
22+
user_guess = int(user_guess)
23+
24+
else:
25+
print('Please type a number')
26+
continue
27+
28+
if user_guess == random_number:
29+
print("You got it! ")
30+
break
31+
elif user_guess > random_number:
32+
print("You were above the number!")
33+
else:
34+
print("You were below the number!")
35+
36+
print("You got it in", guesses, "guesses")

0 commit comments

Comments
 (0)