您的位置:首页 > 编程语言 > Python开发

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

2017-11-05 17:28 761 查看
>>> 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))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息