在疫情期间,各个小区居民发挥互助精神,进行物品交换,互通有无。请你编写一个物品交换软件
该程序允许添加物品的信息,删除物品的信息,显示物品列表,也允许查找物品的信息
你实现的程序可以采用命令行方式使用,但是鼓励提供GUI
PSP数据统计
Item | Time |
---|---|
Planning | |
Estimate | 8min |
Development | |
Analysis | 8min |
Design Spec | 0 |
Design Review | 0 |
Coding Standard | 0 |
Design | 45min |
Coding | 3h |
Code Review | 25min |
Test | 25min |
Reporting | |
Test report | 0 |
Size Measurement | 25min |
Postmortern | 15min |
Process Improvement Plan | 15min |
Main文件
from stock import Stock
s = Stock()
print('-' * 20 + 'The Menu' + '-' * 20)
print('1.Add your product\n2.Delete product\n3.Search for one product\n4.List all the product in stock\n5.Exit')
while True:
try:
info = eval(input('Please select the service you would like:'))
if info == 1:
s.UserAdd()
elif info == 2:
s.UserDelete()
elif info == 3:
s.Search()
elif info == 4:
s.ListAll()
elif info == 5:
print('Thanks for using!')
break
else:
print("Error for input!")
except NameError:
print("Error for input!")
物品类
class Product:
def __init__(self, name, master):
self.name = name
self.master = master
仓储类
from product import Product
class Stock(object):
def __init__(self):
self.goods = []
def Add(self, product):
self.goods.append(product)
def Search(self):
name = input('What product do you want to search for?')
flag = False
for i in range(len(self.goods)):
if self.goods[i].name == name:
flag = True
break
if flag == True:
print('The product you want to search is here:')
print('-' * 50)
for i in range(len(self.goods)):
if self.goods[i].name == name:
print('Product:' + self.goods[i].name + ' Supplier:' + self.goods[i].master)
else:
print('There is no such product.')
def ListAll(self):
if len(self.goods) == 0:
print('There is nothing!')
else:
print('-' * 20 + 'The Stock List' + '-' * 20)
for i in range(len(self.goods)):
print('Product:'+ self.goods[i].name + ' Supplier:' + self.goods[i].master)
def UserAdd(self):
name = input('please enter product:')
master = input('please enter your name:')
p = Product(name, master)
self.Add(p)
def UserDelete(self):
print('Please enter the information of product which you want to delete.')
name = input('please enter your product:')
master = input('please enter your name:')
for item in self.goods:
if name == item.name and master == item.master:
self.goods.remove(item)
Github链接:
https://github.com/zousiyuan777/Help-each-other-in-coronavirus
标签:product,goods,name,python,self,print,程序语言,master,我助 From: https://www.cnblogs.com/zousiyuan/p/16760428.html