-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguessTheNumber.py
More file actions
38 lines (29 loc) · 1.3 KB
/
guessTheNumber.py
File metadata and controls
38 lines (29 loc) · 1.3 KB
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
import random
def guess(x):
random_number = random.randrange(x)
chance = 0
guess = int(input(f"Guess a number between 1 to {x}:"))
while guess != random_number:
chance += 1
if chance != 5:
if guess < random_number:
if chance == 4:
print("nope, that's not correct. Too low.")
guess = int(input(f"----This is the last chance----Guess a number between 1 to {x} again:"))
else:
print("nope, that's not correct. Too low.")
guess = int(input(f"Guess a number between 1 to {x} again:"))
else:
if chance == 4:
print("nope, that's not correct. Too high.")
guess = int(input(f"----This is the last chance----Guess a number between 1 to {x} again:"))
else:
print("nope, that's not correct. Too high.")
guess = int(input(f"Guess a number between 1 to {x} again:"))
else:
print("You Lost!!")
break
if guess == random_number:
print(f"yeah, congratualtions. You guessed it, the number was {guess} ")
rangee = int(input("Enter the range in which you want to guess: "))
guess(rangee)