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

全部博文(150)

文章存档

2012年(2)

2011年(148)

分类: Python/Ruby

2011-07-23 17:46:15

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

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

  6. stack=[]

  7. def pushit():
  8.     stack.append(raw_input('Enter New string :').strip())
  9.     
  10. def popit():
  11.     if len(stack)==0:
  12.         print 'Cannot pop from an empty stack !'
  13.     else:
  14.         print 'Removed [' , `stack.pop()` , '] '
  15.         
  16. def viewstack():
  17.     print stack
  18.     
  19. CMDs={'u':pushit,'o':popit,'v':viewstack}

  20. def showmenu():
  21.     pr="""
  22. p(U)sh
  23. P(O)P
  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 'uovq':
  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()
阅读(927) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~