-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomputer_guess.py
More file actions
28 lines (25 loc) · 797 Bytes
/
Copy pathcomputer_guess.py
File metadata and controls
28 lines (25 loc) · 797 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
from itertools import count
import random
def guess(x):
low = 1
high = x
feedback = ''
print(f'guess number in between {low} and {high}')
count = 0
while count<3:
if low != high:
random_number = random.randint(low, high)
else:
random_number = low
feedback = input(f"{random_number} is too high or too low or correct comparing to guess ")
count+=1
if(feedback == 'l'):
low = random_number + 1
elif(feedback == 'h'):
high = random_number - 1
elif(feedback == 'c'):
print(f'computer guessed your number and that is {random_number}')
break
if count>=3:
print("you won! congrats computer failed to guess your answer")
guess(10)