python基础一 ------简单队列用作历史记录
#需求:测试历史记录,一个猜字游戏,能在重新进入游戏时查看输入历史
#
1 #-*-coding:utf-8-*- 2 from random import randint 3 from collections import deque 4 import pickle 5 guess_num = randint(0,100) 6 7 history = deque([],5) 8 9 while(True): 10 num = input("请输入你猜的数字\n") 11 if num == "history": 12 13 print(history) 14 try: 15 num = int(num) 16 except: 17 print(history) 18 19 history.append(num) 20 21 22 if num == guess_num: 23 print("猜对了") 24 break 25 elif num<guess_num: 26 print("小了") 27 elif num>guess_num: 28 print("大了") 29 30