1.实现栈
class Stack():
def __init__(self):
self.stack = []
def push(self,value):
self.stack.append(value)
return True
def pop(self):
#先判断栈是否为空
if self.stack:
item = self.stack.pop()
return item
else:
return False
def top(self):
if self.stack:
return self.stack[-1]
else:
return False
def length(self):
return len(self.stack)
def view(self):
return ','.join(self.stack)
s = Stack()
s.push('1')
s.push('2')
item = s.pop()
print(s.view())
结果:
1
2.图书管理系统
1.查询图书
2.增加图书
3.借阅图书
4.归还图书
5.退出系统
class Book(object):
def __init__(self, name, author, status, bookindex):
self.name = name
self.author = author
self.status = status