Python实现用户的历史记录功能

Jackey Python 1,391 次浏览 没有评论
# 用户历史记录功能
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))

 

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Go