Chinaunix首页 | 论坛 | 博客
  • 博客访问: 361748
  • 博文数量: 150
  • 博客积分: 3423
  • 博客等级: 中校
  • 技术积分: 1005
  • 用 户 组: 普通用户
  • 注册时间: 2011-07-15 09:04
文章分类

全部博文(150)

文章存档

2012年(2)

2011年(148)

分类: Python/Ruby

2011-07-23 18:01:05

  1. '''
  2. Created on 2011-7-23

  3. @author: Administrator
  4. '''
  5. #!/usr/bin/env python

  6. queue=[]

  7. def enQ():
  8.     queue.append(raw_input('Enter New string :').strip())
  9.     
  10. def deQ():
  11.     if len(queue)==0:
  12.         print 'Cannot pop from an empty queue !'
  13.     else:
  14.         print 'Removed [' , `queue.pop(0)` , '] '
  15.         
  16. def viewQ():
  17.     print queue
  18.     
  19. CMDs={'e':enQ,'d':deQ,'v':viewQ}

  20. def showmenu():
  21.     pr="""
  22. (E)nqueue
  23. (D)nqueue
  24. (V)iew
  25. (Q)uit
  26. Enter choice:"""
  27.     while True:
  28.         while True:
  29.             try:
  30.                 choice=raw_input(pr).strip()[0].lower()
  31.             except:
  32.                 choice='q'
  33.             print '\n You pickde: [%s]' %choice
  34.             if choice not in 'devq':
  35.                 print 'Invalid option ,try again'
  36.             else:
  37.                 break
  38.         if choice =='q':
  39.             break
  40.         CMDs[choice]()
  41. if __name__== '__main__' :
  42.     showmenu()
阅读(527) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~