Python高级编程-如何实现用户的历史记录功能?

来源:互联网 发布:分布式系统 云计算 编辑:程序博客网 时间:2024/06/05 03:08
>>> from collections import deque>>> q=deque([],6)>>> q.append(1)>>> qdeque([1], maxlen=6)>>> q.append(2)>>> q.append(3)>>> q.append(4)>>> q.append(5)>>> q.append(6)>>> qdeque([1, 2, 3, 4, 5, 6], maxlen=6)>>>from random import randintfrom collections import dequeN=randint(0,100)history = deque([],6)def guess (k):    if k== N:        print ('right')        return True    if k<N:        print ('%s is less'%k)    else:        print ('%s is more'%k)    return Falsewhile True :    line =input ("请输入你的数字")    if line.isdigit():        k=int (line)        history.append(k)        if guess (k):            break    elif line =='history' or line == 'h?':        print (list(history))

阅读全文
0 0
原创粉丝点击