-
-
Notifications
You must be signed in to change notification settings - Fork 50.5k
Expand file tree
/
Copy pathguess_the_number_userplay.py
More file actions
33 lines (26 loc) · 837 Bytes
/
guess_the_number_userplay.py
File metadata and controls
33 lines (26 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import random
def guess():
print("🎯 Welcome to Guess the Number game!")
print("Rules are simple, guess a number between 0 and 20, and enter it below.")
print("Only 5 Attempts are possible")
print()
computer = random.choice(range(21))
print("Alright, let’s go! Type your first guess 👇")
print()
print(computer)
count = 0
while True:
user = int(input("Number: "))
if count == 5:
print("Try again, max only 5 Attempts")
break
if user == computer:
print("🔥 Success! You've guessed it right!")
break
elif user < computer:
print("Try some higher numbers!")
count += 1
elif user > computer:
print("Not that high, try lower ones!")
count += 1
guess()