-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2-6.py
More file actions
50 lines (45 loc) · 1012 Bytes
/
2-6.py
File metadata and controls
50 lines (45 loc) · 1012 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
40
41
42
43
44
45
46
47
48
49
50
# coding: utf-8
"""
用户的历史记录功能
"""
from random import randint
from collections import deque
# d = deque([], 5)
# d.append(1)
# d.append(2)
# d.append(3)
# d.append(4)
# d.append(5)
# print d
# d.append(6)
# print d
N = randint(0, 100)
import pickle
# 将对象存在文件
# pick.dump(q, open("hi"), 'w')
# pick.load(open('hi'))
history = deque([], 5)
def guess(k):
if k == N:
print "right"
return True
if k < N:
print "less"
else:
print "greater"
return False
while True:
line = raw_input("please input a number: ")
if line.isdigit():
k = int(line)
history.append(k)
pickle.dump(list(history), open('history','w'))
if guess(k):
break
elif line == 'history' or line == "h?":
# print list(history)
with open('history') as f:
data = pickle.load(f)
print data
elif line == 'quit':
break