Skip to content

Commit a092e9e

Browse files
Added a python program where you can play a game, You just haveto guess the number the computer has randomly chosen , you have only 5 tries and the number lies in between 1 and 50. It gives an idea of how close you are to guessing the number by saying YOU GUESSED TOO SMALL or YOU GUESSED TOO HIGH.
1 parent 3632487 commit a092e9e

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)