>>> from collections import deque
>>> q=deque([],6)
>>> q.append(1)
>>> q
deque([1], maxlen=6)
>>> q.append(2)
>>> q.append(3)
>>> q.append(4)
>>> q.append(5)
>>> q.append(6)
>>> q
deque([1, 2, 3, 4, 5, 6], maxlen=6)
>>>
from random import randint
from collections import deque
N=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 False
while 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))
Python高级编程-如何实现用户的历史记录功能?
最新推荐文章于 2020-07-02 17:25:25 发布