Chinaunix首页 | 论坛 | 博客
  • 博客访问: 262973
  • 博文数量: 30
  • 博客积分: 380
  • 博客等级: 一等列兵
  • 技术积分: 477
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-30 21:28
文章分类

全部博文(30)

文章存档

2014年(2)

2013年(13)

2012年(15)

分类: 系统运维

2013-12-20 16:47:09

#!/usr/bin/python


stack = []


def pushit():
        stack.append(raw_input('Enter new string: ').strip())


def popit():
        if len(stack) == 0:
                print 'Cannot pop from an empty stack!'
        else:
                print 'Remove [', `stack.pop()`, ']'


def viewstack():
        print stack #calls str() internally


CMDs = {'u': pushit, 'o': popit, 'v': viewstack}


def showmenu():
        pr = """


p(U)sh
p(O)p
(V)iew
(Q)uit


Enter choice: """


        while True:
                while True:
                        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'
                        else:
                                break
                if choice == 'q':
                        break
                CMDs[choice]()
if __name__ == '__main__':
        showmenu()


阅读(2110) | 评论(0) | 转发(0) |
0

上一篇:test-变量.py

下一篇:《员工价值》

给主人留下些什么吧!~~