标签:python
#!/usr/bin/env 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: r=stack.pop() print "Removed [ %s]" %r def viewstatck(): print stack CMDs = {‘u‘:pushit,‘o‘:popit,‘v‘:viewstatck} def showmenu(): pr=""" p(U)sh P(O)p (V)iew (Q)uit Enter choice:""" while True: choice = raw_input(pr).strip()[0].lower() print "\nYou picked:[%s]"%choice if choice == ‘q‘: break if choice not in ‘uovq‘: print ‘Invalid option,tyr again‘ continue else: CMDs[choice]() if __name__ == ‘__main__‘: showmenu()
本文出自 “服务器” 博客,请务必保留此出处http://zhangfang2012.blog.51cto.com/6380212/1674853
标签:python
原文地址:http://zhangfang2012.blog.51cto.com/6380212/1674853