-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimproved_guessing_game.py
22 lines (20 loc) · 1.01 KB
/
improved_guessing_game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import random
max_number = int(input('I will choose a number between one and whatever maximum you set. Please choose the maximum number now: ' ))
done = False
while not done: #This is the loop to keep the game going even after a successful guess. It resets the random number and starts it over
n = random.randint(1, max_number)
guess = False
while guess == False: #This is the loop that will let the player keep guessing if they guess wrong the first time.
ans = int(input('Enter your guess - or enter "0" to quit: '))
if ans == 0:
print('Thank you for playing!')
done = True #This breaks the game loop
break #This is to break the guessing loop
else:
if ans == n:
print('Success you win! I will now choose another number.')
guess = True
elif ans > n:
print('That is too high. Guess again!')
else:
print('That is too low. Keep guessing!')