python 列表模拟堆栰
#!/usr/bin/env pythonstack = []
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().lower()
print "\nYou picked:[%s]"%choice
if choice == 'q':
break
if choice not in 'uovq':
print 'Invalid option,tyr again'
continue
else:
CMDs()
if __name__ == '__main__':
showmenu()
页:
[1]