Skip to content

Commit 0ee2033

Browse files
authored
Added a guess the number game
Please accept my pull request
1 parent 9bccf15 commit 0ee2033

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

Guess_the_number.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#https://www.facebook.com/100051921408118/posts/190716086002437/?app=fbl
2+
#Subscribed by CodeHouse
3+
print("Welcome to the guess the number game\n")
4+
5+
print("You have to guess the number\n")
6+
7+
print("Hint : The number is between 1-50\n")
8+
9+
import random
10+
11+
num=random.randint(1,50)
12+
13+
a=7
14+
15+
while a>0:
16+
17+
guess=int(input("Enter your guessed number : ")) if guess==num:
18+
19+
print("You won!")
20+
21+
break
22+
23+
24+
25+
elif guess>num:
26+
27+
print("Too high")
28+
29+
a=a-1
30+
31+
print("You are left with ",a,"guesses\n")
32+
33+
continue
34+
35+
36+
37+
elif guess<num:
38+
39+
print("Too low")
40+
41+
a=a-1
42+
43+
print("You are left with ",a,"guesses\n")
44+
45+
continue
46+
47+
if a==0:
48+
49+
print("You lose! Better luck next time")
50+
51+

0 commit comments

Comments
 (0)