题目要求:
栈的工作原理
入栈
出栈
查看栈顶元素
栈的长度
栈是否为空
代码如下:第一种
menu = '''
1. PUSH
2. POP
3. FIND
4. LENGTH
5. ISEMPTY
6. QUIT
'''
Stack = []
while True:
print(menu)
###PUSH
choose = input('Please Input Your choose:')
if choose == '1':
str = input('Str:')
Stack.append(str)
print('PUSH Successful')
###POP
elif choose == '2':
if len(Stack):
###item = Stack.pop()
###print('%s' %item)
i = Stack.index(Stack[-1])
print(Stack.pop(i))
print('POP Finished')
else:
print('POP Failed')
###FIND
elif choose == '3':
FindName = input('Name: ')
if FindName in Stack:
print('%s is in %s