# 用户历史记录功能 from random import randint from collections import deque import pickle from pip._vendor.distlib.compat import raw_input # 猜数字小游戏 N = randint(0, 100) # 创建5个元素的队列,保留最近五条输入记录 history = deque([], 5) def guess(k): if k == N: print('right') return True if k < N: print('%s is less than N' % k) else: print('%s is greater tha N' % k) return False while True: line = raw_input('please inut a number: ') if line.isdigit(): k = int(line) history.append(k) # 将记录存储到文件 if guess(k): break elif line == 'history' or line == 'h?': print(list(history))