-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
34 lines (25 loc) · 1.05 KB
/
game.py
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
from random import randint
random_value = randint(1, 50)
#DevOption below: display the secret number so you can try the code knowing the answer
#print(random_value)
user_name = input("Hey there, my name is Boot, what is yours? ")
print(user_name, " this is how it's gonna work:")
print("You will have 5 chances to guess the secret number that I am thinking of in a range between 1 and 50, got it?")
print("Let's game \n")
user_attempts = 4
for i in range(5):
user_guess = int(input("So wich number do you have in mind? "))
won = (user_guess == random_value)
guessBigger = (user_guess > random_value)
if (won):
print(user_name, "congrats, you've won!")
break
elif (guessBigger):
print("Sorry, I though of a number a little bit smaller")
else:
print("Sorry, I though of a number a little bit bigger")
if (user_attempts == 0):
print("Unfortunately you ran out of chances, the correct answer was: ", random_value)
break
print("Attempts left: ", user_attempts)
user_attempts-=1