-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumber_Guessing_Game.py
More file actions
39 lines (25 loc) · 987 Bytes
/
Number_Guessing_Game.py
File metadata and controls
39 lines (25 loc) · 987 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
34
35
36
37
38
39
import random
target = random.randint(0,50)
chances = 1
print("-----GAME START-----")
while(chances<=3):
guess_num = input(f"Guess the number between 0-50 or Quit, This is your {chances} chance ")
if guess_num.lower()== "quit":
print(f" You are choosing to Quit. \n The random number was : {target} \n THANK YOU FOR PLAYING ")
break
if not guess_num.isdigit():
print("Invalid input! Please enter a number between 0-50 or type Quit.")
continue
guess_num = int(guess_num)
if guess_num == target:
print("You Won: You have successfully guessed the number")
break
elif guess_num < target:
print("Nope, Your number is small. TRY AGAIN!")
else:
print("Nope, Your number is big. TRY AGAIN!")
chances+=1
if (chances > 3):
print(f"YOU LOST! You have used all your chances :(")
print(f"The number was {target}")
print("-----GAME OVER----")