首页 > 编程语言 >你帮我助”软件开发 (以python为程序语言)

你帮我助”软件开发 (以python为程序语言)

时间:2022-10-07 19:15:54浏览次数:51  
标签:product goods name python self print 程序语言 master 我助

在疫情期间,各个小区居民发挥互助精神,进行物品交换,互通有无。请你编写一个物品交换软件

该程序允许添加物品的信息,删除物品的信息,显示物品列表,也允许查找物品的信息

你实现的程序可以采用命令行方式使用,但是鼓励提供GUI

PSP数据统计

ItemTime
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

相关文章

  • aardio多线程调用python防止界面卡顿
    在aardio中使用多线程目录在aardio中使用多线程问题多线程python里的多线程尝试直接把这个放到aardio里面GIL锁存钱取钱问题aardio给出的案例调用的步骤代替解决......
  • Pythontext_4
    1实例一:使用字符串拼接输出一个关于程序员的笑话2programmer_1='程序员甲:搞IT太幸苦了,我想换行……怎么办?'3programmer_2='程序员乙:敲一下回车键'4print(progr......
  • 入门神经网络-Python 实现(下)
    假设对BP的认识回顾紧接着上篇,整到了,MES的公式和代码的实现.\(MSE=\frac{1}{n}\sum\limits_{i=1}^n(y_i-\haty_i)^2\)n表示样本数,这......
  • 代码视角-神经网络-Python 实现(上)
    巩固神经网络的入门知识,从代码上来认识这些概念会轻松很多.说明:就是巩固一下认识而已,也是找了篇网上大佬的文章,看了下写得还行,抄一抄,......
  • 补充(代码)-入门神经网络-Python 实现(下)
    以案例+公式推导+代码编写,来走一遍神经网络的FG,BP算法.回顾紧接着上篇,整到了,MES的公式和代码的实现.\(MSE=\frac{1}{n}\sum\limi......
  • 【python爬虫】 python 爬取知乎的公开收藏夹
    前言看看如何用python爬取知乎的公开收藏夹内容尝试第一个方法开始的时候用python,request库进行的网页请求,在请求你的收藏夹总界面的时候还可以返回信息,这个ur......
  • python3 time和datetime
    Python中表示时间的两种方式:1.时间戳:相对于1970.1.100:00:00以秒计算的偏移量,唯一的2.时间元组struct_time:共有9个元素tm_year:年1-12tm_mon:月1-12tm_mday:......
  • 对比python学julia(第四章:人工智能)--(第三节)目标检测
    1.1. 项目简介目标检测(ObjectDetection)的任务是在图像中找出检测对象的位置和犬小,是计算机视觉领域的核心问题之一,在自动驾驶、机器人和无人机等许多领域极具......
  • Python示例——负数的位运算
    平时在coding的时候虽然会遇到位运算但一般也都是正数的位运算,今天突然见到了使用负数的位运算,对此十分好奇和困惑,为此做了下了解,于是有了此文。 给出一些位运算的例子:  ......
  • 再探 游戏 《 2048 》 —— AI方法—— 缘起、缘灭(6) —— Python版本实现的《2048》
    《2048》游戏在线试玩地址:​​https://play2048.co/​​  如何解决《2048》游戏源于外网的一个讨论帖子,而这个帖子则是讨论如何解决该游戏的最早开始,可谓是“缘起”:What......