栈的工作原理
1.入栈 append
2.出栈 pop
3.栈顶元素
4. 栈的长度 len
5.栈是否为空 len == 0
s=[1,2,3,5,6]
info="""======栈的工作原理======
1.入栈
2.出栈
3.查找栈顶元素
4.栈的长度
5。栈是否为空"""
while True:
print(info)
choice=input("Please Input your choice:")
if choice=='1':
t=input("请输入入栈元素:")
s.append(t)
print(s)
print("入栈成功!")
elif choice=='2':
if not s:
print("栈不能为空,不能出栈!")
else:
t=input("请输入出栈元素:")
s.append(t)
print(s)
print("出栈成功!")
elif choice=='3':
if len(s)==0:
print("该栈为空,没有栈顶元素!")
else:
k=s[-1]
print("栈顶元素为:%s"%k)
elif choice=='4':
l=len(s)
print("栈的长度为:%s"%l)
elif choice=='5':
if len(s)==0:
print("该栈为空!")
else:
print("该栈不为空!")