Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use python to realize inventory Management system

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to use python to achieve inventory commodity management system related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that after reading this article on how to use python to achieve inventory commodity management system will have a harvest, let's take a look.

The requirements of the topic:

Please design a commodity management system, the program is required to enter the corresponding functional module according to the options entered by the user, and display the corresponding prompt information. If the user enters other options, the prompt is "incorrectly entered".

The functional modules of the program are:

1. Add

The program reads the goodinformation.txt under the source file path and creates it if not. When the added item already exists, it displays "the item already exists"

2. Query

According to the product name entered by the user, the commodity information is queried and output. When the queried item does not exist, it displays "there is no such item in the commodity library".

3. Statistics

According to the data in goodinformation.xt, generate statistics, including (type of goods, total number of goods, total sales, average price of goods), and write them into goodtotal.txt

4. Quit

Exit the run.

Tip:

Opening and reading of dictionaries, lists, functions, files, etc.

The requirements are as follows:

1. If the specific functional code cannot be implemented, then complete the program architecture, such as listing the required functions and adding appropriate comments.

two。 Add test cases, that is, according to the topic function, you can specify that if the input is XXX, the output should be YYY.

In order to enhance the robustness of the program, the re module is used to prevent the input and output from being unrecognized by comma punctuation marks.

# suppose the data in the file is written as follows: blueberry, 10pm 20 (data per line)

Import re

Def read_goods (fn):

Fdic = {}

With open (fn, "r") as f:

For i in f.readlines ():

Goodl = list (re.split (r "[,]", I))

Goodl = [x.strip () for x in goodl]

Fdic [goodl [0]] = goodl

Return fdic

Def add_goods (fdic, fn):

Goods_list = list (re.split ('[,]', input ("Please enter commodity information (commodity name, unit price, quantity), enter exit:"))

If goods_list [0] = "":

Return 0

Elif len (goods_list) = = 3:

Try:

A = eval (goods_list [1]) + eval (goods_list [2]) # prevent non-numeric symbols from being entered when entering prices

Except NameError:

Print ("Please enter a numeric symbol for price")

Else:

If goods_list [0] in fdic.keys ():

Print ("this item already exists")

Else:

FDIC [goods_list _ list [0]] = FDIC

With open (fn, "a") as f:

F.writelines (', '.join (goods_list))

F.write ("\ n")

Add_goods (fdic, fn)

Else:

If goods_list [0] in fdic.keys ():

Print ("this item already exists")

Else:

Print ("input error please re-enter")

Add_goods (fdic, fn)

Def find_goods (fdic):

While True:

Good_name = input ("Please enter the name of the queried product and enter enter to exit:")

If good_name = "":

Break

Else:

For k in fdic.keys ():

If k = = good_name:

Print ("{}, {: .2f}" .format (k, eval (fdic [k] [2])

Find_goods (fdic)

Return 0

Print ("there is no such item in the product library")

Def count (fdic, fn):

Type_amount = len (fdic)

Good_amount, total_sales, sum_price, ave_price = 0,0,0,0

For v in fdic.values ():

Good_amount + = eval (v [2])

Total_sales + = eval (v [2]) * eval (v [1])

Sum_price + = eval (v [1])

Try:

Ave_price = sum_price / type_amount

With open (fn, "w") as f:

Text = "Commodity:" + str (type_amount) +\

"\ nTotal number of goods:" + str (good_amount) +\

"\ nTotal sales:" + str (total_sales) +\

"\ nCommodity average price:" + str (ave_price)

F.write (text)

Except ZeroDivisionError:

With open (fn, "w +") as f:

F.seek (0)

Text = "Commodity category: 0\ nTotal merchandise: 0\ nTotal sales: 0\ nCommodity average price: 0"

F.write (text)

Return print ("Commodity statistics have been written to statistics file")

Def main ():

Goodinfo = "C:\\ Users\\ 13935\\ Desktop\\ goodinformation.txt" # replace it with your own path

Goodtotal = "C:\\ Users\\ 13935\\ Desktop\\ goodtotle.txt" # replace it with your own path

Goods_dict = read_goods (goodinfo)

Print ("1. Query goods\ n2. Add goods\ n3. Statistical goods\ n4. Exit\ n")

While True:

Try:

Info = eval (input ('Please enter your choice:')

If info = = 1:

Find_goods (goods_dict)

Elif info = = 2:

Add_goods (goods_dict, goodinfo)

Elif info = = 3:

Count (goods_dict, goodtotal)

Elif info = = 4:

Break

Else:

Print ("input error please re-enter")

Except NameError:

Print ("input error please re-enter")

Return 0

Main ()

Running result:

Generate two files:

This request takes a screenshot and goes below.

This is the end of the article on "how to use python to achieve inventory management system". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to use python to achieve inventory management system". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report