-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuessNumber.py
More file actions
43 lines (37 loc) · 1.03 KB
/
Copy pathGuessNumber.py
File metadata and controls
43 lines (37 loc) · 1.03 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
40
41
42
43
import random
class GuessNumber:
def __init__(self):
self.reset()
def reset(self):
self.target = random.randint(1, 100)
self.min = 1
self.max = 100
self.count = 0
self.finish = False
def guess(self, number):
self.count += 1
if self.target == number:
self.finish = True
return {
'finish': self.finish,
'target': self.target,
'count': self.count
}
else:
if number > self.target:
self.max = number - 1
else:
self.min = number + 1
return {
'finish': self.finish,
'count': self.count,
'min': self.min,
'max': self.max
}
def report(self):
return {
'min': self.min,
'max': self.max,
'count': self.count,
'finish': self.finish
}