-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguessing_game.py
More file actions
33 lines (26 loc) · 857 Bytes
/
guessing_game.py
File metadata and controls
33 lines (26 loc) · 857 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
random_number = random.randint(1, 10)
chances_amount = 3
guessed_amount = 0
def prompt_for_input():
print("I've chosen a number between 1 and 10!")
print("You've guessed {} times and have {} guesses left.".format(guessed_amount, chances_amount))
while chances_amount > 0:
prompt_for_input()
try:
user_guess = int(input("> "))
except:
print("Oops! That wasn't a whole number!")
break
chances_amount -= 1
guessed_amount += 1
if user_guess == random_number:
print("Yup! I chose {}!".format(random_number))
print("It took you {} tries!".format(guessed_amount))
break
elif user_guess < random_number:
print("You guessed too low!")
continue
elif user_guess > random_number:
print("You guessed too high!")
continue