代码拉取完成,页面将自动刷新
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'把列表用做队列:列队的特点为先入先出(FIFO)。'
queue = []
# 添加元素
def enQ():
queue.append(raw_input(' 输入新的字符: ').strip())
# 出队列
def deQ():
if len(queue) == 0:
print '不能从空的队列中移除元素'
else:
print '移除 [', `queue.pop(0)`, ']'
# 查看
def viewQ():
print('目前列队为:'),
print(queue)
CMDs = {'e':enQ, 'd':deQ, 'v':viewQ}
# 显示菜单
def showmenu():
pr = '''
(E)nqueue
(D)equeue
(V)iew
(Q)uit
输入你的选择(e:入列队/d:出列队/v:查看列队/q:退出):'''
while True:
while True:
try:
choice = raw_input(pr).strip()[0].lower()
except (EOFError,KeyboardInterrupt,IndexError):
choice = 'q'
print '\n你选择的操作是: [%s]' % choice
if choice not in 'edvq':
print ('无效输入,请按要求重新输入')
else:
break
if choice == 'q':
print('感谢您的使用,编程愉快!')
break
CMDs[choice]()
if __name__ == '__main__':
showmenu()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。