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
This repository was archived by the owner on May 25, 2022. It is now read-only.

Commit f5cdcf8

Browse files
Merge pull request #205 from leader2one/javokhir
Added the project for the issue #198
2 parents d13b8d8 + bfa6ff6 commit f5cdcf8

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Number Guessing Game
2+
3+
This game allows you to check your luck and intuition :)
4+
You should find the number computer guessed
5+
6+
### Usage
7+
Just run "python main.py" in cmd command line after setting the project directory
8+
9+
### Here you can see sample
10+
![Image](./image.png)
11+
12+
## *Author Name*
13+
14+
[Javokhir](https://github.com/leader2one/)
9.32 KB
Loading[フレーム]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import random
2+
3+
print("Number guessing game")
4+
5+
# randint function to generate the
6+
# random number b/w 1 to 9
7+
number = random.randint(1, 9)
8+
9+
# number of chances to be given
10+
# to the user to guess the number
11+
# or it is the inputs given by user
12+
# into input box here number of
13+
# chances are 5
14+
chances = 0
15+
16+
print("Guess a number (between 1 and 9):")
17+
18+
# While loop to count the number
19+
# of chances
20+
while True:
21+
22+
# Enter a number between 1 to 9
23+
guess = int(input())
24+
25+
# Compare the user entered number
26+
# with the number to be guessed
27+
if guess == number:
28+
29+
# if number entered by user
30+
# is same as the generated
31+
# number by randint function then
32+
# break from loop using loop
33+
# control statement "break"
34+
print(
35+
f'CONGRATULATIONS! YOU HAVE GUESSED THE \
36+
NUMBER {number} IN {chances} ATTEMPTS!')
37+
# Printing final statement using the f-strings method;
38+
break
39+
40+
# Check if the user entered
41+
# number is smaller than
42+
# the generated number
43+
elif guess < number:
44+
print("Your guess was too low: Guess a number higher than", guess)
45+
46+
# The user entered number is
47+
# greater than the generated
48+
# number
49+
else:
50+
print("Your guess was too high: Guess a number lower than", guess)
51+
52+
# Increase the value of chance by 1
53+
chances += 1
54+

0 commit comments

Comments
(0)

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