-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCode.txt
More file actions
39 lines (36 loc) · 1.76 KB
/
Copy pathCode.txt
File metadata and controls
39 lines (36 loc) · 1.76 KB
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
num = random.randint(1,100)
print("WELCOME TO GUESS ME!")
print("Let me select a number between 1 and 100")
print("If your guess is more than 10 away from my number, I'll tell you you're COLD")
print("If your guess is within 10 of my number, I'll tell you you're WARM")
print("If your guess is farther than your most recent guess, I'll say you're getting COLDER")
print("If your guess is closer than your most recent guess, I'll say you're getting WARMER")
print("LET'S PLAY!")
guesses=[0]
while(True):
guess = int(input('Make your guess\n'))
if guess<1 or guess>100:
print("OUT OF BOUNDS!")
continue
if guess==num:
print('CONGRATULATIONS!, you guessed the correct answer in {} attempts.\n'.format(len(guesses)))
break
guesses.append(guess) # all the incorrect guesses are added to list
if len(guesses)>10: # after nine trials player may choose to know the answer
temp = int(input('Do you want to know the answer?\nPress 1 for Yes and 0 to continue\n'))
if temp == 1:
print(num)
print('Try next time, Cheers!')
break
if guesses[-2]==0: # when testing the first guess, guesses[-2]==0, which evaluates to False
# and brings us down to the second section
if abs(num-guess) < abs(num-guesses[-2]):
print('WARMER!')
else:
print('COLDER!')
else:
if abs(num-guess) <= 10:
print('WARM!')
else:
print('COLD!')