#!/usr/bin/env  python
stack=[]
def pushit():
    stack.append(rav_input('enter new string:').strip())
def popit():
  if len(stack)==0:
     print 'cannot pop from an empty stack!'
  else:
     print 'removed[','stack.pop()',']'
def viewstack():
     print stack
CMDs={'u':pushit,'o':popit,'v':viewstack}
def showmenu():
    pr="""
    p(u)sh
    p(O)p
    (v)iew
    (q)uit
    enter choice:"""
while Ture:
     while Ture:
        try:
            choice =raw_input(pr).strip()[0].lower()
        except(eoferror,keyboardinterrupt,indexerror):
            choice='q'
            print '\nyou picked:[%s]'%choice
if choice not in 'uovq':
    print 'invalid option,try again'
CMDs[choice]()
if name_ == '_main_':
    showmenu()
    
  • 盛世龙腾    2018-06-20 15:44:43
  • 阅读 585    收藏 0    回答 2
  • 邀请
  • 收藏
  • 分享
发送
登录 后发表评论
  • 51testing软件测试圈微信