软件要求
在疫情期间,各个小区居民发挥互助精神,进行物品交换,互通有无。请你编写一个物品交换软件
该程序允许添加物品的信息,删除物品的信息,显示物品列表,也允许查找物品的信息
你实现的程序可以采用命令行方式使用,但是鼓励提供GUI
使用环境
IDE:Pycharm
环境:Python 3.7
PSP数据分析
Item | Time |
---|---|
Planning | |
Estimate | 5min |
Development | |
Analysis | 5min |
Design Spec | 0 |
Design Review | 0 |
Coding Standard | 0 |
Design | 30min |
Coding | 2h |
Code Review | 10min |
Test | 10min |
Reporting | |
Test report | 0 |
Size Measurement | 10min |
Postmortern | 5min |
Process Improvement Plan | 5min |
功能介绍
“你帮我助”物品互换平台主要基于命令行完成用户与数据的交互。
用户通过命令行中显示的服务序号可以选择相应的功能。
例如:添加物品、删除物品、查找物品、显示全部物品。
代码
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/RebelHu/YouHelpMeHelp
标签:product,goods,name,软件开发,self,print,master,我助 From: https://www.cnblogs.com/yohanceblog/p/16758197.html