-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguessTheNum.py
More file actions
29 lines (21 loc) · 796 Bytes
/
guessTheNum.py
File metadata and controls
29 lines (21 loc) · 796 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
# This is a guess the number game + try // catch.
import random
secretNumber = random.randint(1, 100)
print('I am thinking of a number between 1 and 100.')
# Ask the player to guess 6 times.
try:
for guessesTaken in range(1, 7):
print('Take a guess.')
guess = int(input())
if guess < secretNumber:
print('Your guess is too low.')
elif guess > secretNumber:
print('Your guess is too high.')
else:
break # This condition is the correct guess!
if guess == secretNumber:
print('Good job! You guessed my number in ' + str(guessesTaken) + ' guesses!')
else:
print('Nope. The number I was thinking of was ' + str(secretNumber))
except ValueError:
print('No guesses taken. Try again')