Skip to content

Commit 7b97a06

Browse files
add guess_the_number_userplay.py
1 parent ae68a78 commit 7b97a06

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

other/guess_the_number_userplay

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import random
2+
3+
def guess():
4+
print("🎯 Welcome to Guess the Number game!")
5+
print("Rules are simple, guess a number between 0 and 20, and enter it below.")
6+
print("Only 5 Attempts are possible")
7+
print()
8+
9+
10+
computer = random.choice(range(21))
11+
print("Alright, lets go! Type your first guess 👇")
12+
print()
13+
14+
print(computer)
15+
16+
count = 0
17+
while True:
18+
user = int(input("Number: "))
19+
if count == 5:
20+
print("Try again, max only 5 Attempts")
21+
break
22+
if user == computer:
23+
print("🔥 Success! You've guessed it right!")
24+
break
25+
elif user < computer:
26+
print("Try some higher numbers!")
27+
count += 1
28+
elif user > computer:
29+
print("Not that high, try lower ones!")
30+
count += 1
31+
32+
33+
34+
guess()

0 commit comments

Comments
 (0)