forked from ianbuen/PythonExercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08 GuessTheNumber.py
More file actions
39 lines (30 loc) · 882 Bytes
/
08 GuessTheNumber.py
File metadata and controls
39 lines (30 loc) · 882 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
gameOver = False
num = random.randint(1, 100)
tries = 0
# GAME LOOP
while not gameOver:
print("\n\nGUESS THE NUMBER GAME!!")
guess = input("What's your guess? (1 - 100): ")
if guess.lower().strip() == 'exit':
win = False
gameOver = True
elif guess.isdigit() and int(guess) > 0 and int(guess) < 101:
if int(guess) < num:
print("\nHigher!")
elif int(guess) > num:
print("\nLower!")
elif int(guess) == num:
win = True
gameOver = True
else:
print("Invalid input.")
tries += 1
else:
print("\n\nGAME OVER!!")
if win:
print("YOU WIN!! IT'S %s" % num)
else:
print("You quit the game.")
print("Number of tries: %s" % tries)
#END GAME LOOP