1、修改用户登录系统
2、栈功能的显示
两者二选一提交运行过程和结果。功能要求如下图:
多加注释
class Stack(object):
"""栈"""
def __init__(self):
self.items = []
def is_empty(self):
return self.items == []
def push(self, item):
self.items.append(item)
def pop(self):
return self.items.pop()
def peek(self):
return self.items[len(self.items)-1]
def size(self):
return len(self.items)
def display(self):
print(self.items)
if __name__ == "__main__":
stack = Stack()
while True:
print("1.入栈")
print("2.出栈")
print("3.查看栈顶元素")
print("4.查看栈长度")
print("5.查看栈中元素")
print("6.退出")
str = input("请选择操作:")
if str == '1':
s = input("请输入入栈元素:")
stack.push(s)
elif str == '2':
if stack.is_empty():
print("栈为空")
else:
print("出栈元素:" + stack.pop())
elif str == '3':
if stack.is_empty():
print("栈为空")
else:
print("栈顶元素:"+ stack.peak())
elif str == '4':
print("栈长度:%d "% stack.size())
elif str == '5':
print("栈中元素:")
stack.display()
elif str== '6':
print("程序结束!")
break
else:
print("选择有误,请重新输入!")