# 很多应用程序都有浏览用户的历史记录的功能,
# 例如:
# 浏览器可以查看最近访问过的网页,
# 视频播放器可以查看最近播放过的视频文件
# Shell可以查看用户输入过的命令
# .....
# 现在我们制作了一个简单的猜数字小游戏,
# 添加历史记录功能,显示用户最近猜过的数字,如何实现?
# 解决方案 使用容量为n的队列储存历史记录
# 使用表针库collections中的deque,他是有一个双端循环队列
# 程序退出前,可以使用pickle将pickle队列对象存入文件,再次运行程序时将其导入,
from random import randint
from collections import deque
from notebook.notebookapp import raw_input
import pickle
import os
def main():
# q=deque([],5)
# for x in range(7):
# q.append(x)
# print(q)
while True:
line=raw_input('plase input a number:')
if line.isdigit():
k=int(line)
if guess(k):
break
elif line=="history.txt" or line=='h?':
print(list(history))
pass
N=randint(0,100)
history = deque([], 5)
def guess(k):
history.append(k)
if(k==N):
print('right')
return True
if k<N:
print("%s is less-than N"%k)
else:
print("%s is greater-than N" % k)
return False
main()
output.close()
output2.close()