Skip to content

Commit 7b8da22

Browse files
Merge pull request raviprakashdev#49 from hasna-akbarali/master
Added a python program where you can play a guessing game,
2 parents 3632487 + a092e9e commit 7b8da22

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

guess_number.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import random
2+
import math
3+
x = random.randint(1,50)
4+
print("\n\tYou've only 5 chances to guess the integer!\n")
5+
count = 0
6+
while count < 5:
7+
count += 1
8+
guess = int(input("Guess a number:- "))
9+
if x == guess:
10+
print("Congratulations you did it in ", count, " try(s)")
11+
# Once guessed, loop will break
12+
break
13+
elif x > guess:
14+
print("You guessed too small!")
15+
elif x < guess:
16+
print("You Guessed too high!")
17+
18+
if count >= 5:
19+
print("\nThe number is %d"%x)
20+
print("\tBetter Luck Next time!")

0 commit comments

Comments
 (0)