Python basic project: supermarket commodity sales management system

Posted by username123 on Sun, 26 Dec 2021 05:55:03 +0100

preface

In 2020, the sales of double 11 reached a new high, of which tmall's sales exceeded 490 billion yuan and JD's sales exceeded 270 billion yuan. At the same time, the rapid development of live e-commerce contributed a lot to the rapid growth of e-commerce sales during the double 11.

In recent years, the double 11 e-commerce shopping festival has become a consumption carnival season in China and even the world. In 2020, major e-commerce companies built the past double 11 into a double sales system, which lengthened the whole activity cycle and turned the "Shopping Festival" into a "shopping season". More and more brands and consumers participated in the shopping carnival. During the double 11 in 2020, The whole network sales record of e-commerce platform was broken again.

1, What is a supermarket shopping and sales management system?

At any time, people always like to visit shopping malls and supermarkets, such as IKEA, RT mart, century Hualian, bubagao, etc. when we see a wide range of things in such a large supermarket, we always have an impulse to move the supermarket home

So, as the manager of the shopping mall, how to know the daily passenger flow and turnover? At this time, the powerful shopping system can easily and efficiently solve many problems and deal with business conveniently

So what should it do?

1. Login verification is required to use the system. After entering the system, enter the shopping budget information
login
2. Users can view commodity information and purchased information at will
View goods, view purchases
3. The user purchases the goods according to the commodity number. When purchasing, check whether the balance is enough, deduct the money directly if it is enough, and remind if it is not enough
purchase
4. You can exit at any time (enter exit). After exiting, print the purchased goods and balance
{'F00001': {'name': 'Apple', 'price': 1.2},
'F00002': {'name': 'Banana', 'price': 5.5},}

The next step is to implement interfaces with different functions:

II

1. Login interface

It is recommended to select admin or root, or switch between administrator and customer

2. View commodity information interface

Here are five kinds of fruits with numbers, names and unit prices

3. Information interface for purchasing goods

What you buy will be displayed

3. View the purchase list

What you buy will be at a glance

4. View balance

This is roughly your ticket interface
5. Exit the system

The specific code is as follows (example):

"""
 1.Login verification is required to use the system. After entering the system, enter the shopping budget information
    login
 2.Users can view commodity information and purchased information at will
    View goods, view purchases
 3.The user purchases the goods according to the commodity number. When purchasing, check whether the balance is enough, deduct the money directly if it is enough, and remind if it is not enough
    purchase
 4.You can exit (enter) at any time exit),After exiting, print the purchased goods and balance
       {'F00001': {'name':'Apple', 'price':1.2},
       'F00002': {'name':'Banana', 'price':5.5}, }
"""
import sys

# Product list
goods = {'F00001': {'name': 'Apple', 'price': 1.2},
         'F00002': {'name': 'Banana', 'price': 5.5},
         'F00003': {'name': 'Grape', 'price': 6.0},
         'F00004': {'name': 'Pear', 'price': 5.0},
         'F00005': {'name': 'watermelon', 'price': 2.5}}


# Login function
def login():
    """
    Verify the user. You can try 3 times
    """
    users = {"admin": "admin", "cali": "123456"}
    for i in range(3):
        username = input("   Please enter your account:")
        passwd = input("   Please input a password:")
        if passwd == users.get(username.strip()):
            print("Welcome to Sanle shopping system".center(30, '*'))
            break
        else:
            print(f"Login failed,You can also try{2 - i}second")
    else:
        print("User locked,Please try again later")
        # When you need to exit the program (script) directly, you can use sys exit(exitcode)
        sys.exit(-1)
        # break


# View all product information
def view_product_info():
    print('View all product information')
    print(f"{'Item number':<7}{'Trade name':<10}{'Unit Price':<7}")
    for item in goods:
        print(f"{item:<10}{goods[item]['name']:<12}{goods[item]['price']:<10}")


# View purchase list
def purchasing_list(shopping_list):
    print('View purchase list')
    print(f"{'Item number':<7}{'Trade name':<10}{'Unit Price':<6}{'quantity':>6}")
    for item in shopping_list:
        print(f"{item:<10}{goods[item]['name']:<12}{goods[item]['price']:<12}"
              f"{shopping_list[item]}")


# Purchase goods
def purchase(balance, shopping_list) -> float:
    number = input("Please enter the item number")
    if number in goods:
        print("Start buying goods")
        quantity = input('Please enter the quantity you want to buy:')
        if quantity.isdigit():
            quantity = int(quantity)
            if quantity * goods[number]['price'] <= balance:
                if number in shopping_list:
                    shopping_list[number] += quantity
                else:
                    shopping_list[number] = quantity
                balance -= quantity * goods[number]['price']
                print("Purchase succeeded, please continue...")
                purchasing_list(shopping_list)
            else:
                print(f"Your current balance is:{balance},If you need to continue to purchase, please continue to recharge")
                money = input("Enter recharge amount")
                if money.isdigit():
                    money = int(money)
                    balance += money
                else:
                    print("Incorrect input")
    else:
        print("Wrong entry of commodity number")
    return balance


"""
menu
"""


def menu():
    print('Sanle shopping system'.center(30, '*'))
    login()

    # Recharge amount = > encapsulation function can also be considered
    credit = input("Please recharge:")
    if credit.isdigit():
        credit = float(credit)
        # balance
        balance = credit
    else:
        print("Recharge failed, please contact the administrator!")
        sys.exit(-2)

    # Purchase list initialization is empty
    shopping_list = {}
    while True:
        operation = """
        Please enter what you want to do:
        1.Enter 1 to view all product information
        2.Enter 2 to purchase the item
        3.Enter 3 to view the purchase list
        4.Enter 4 to view the balance
        5.Enter 5 to exit the system
        """
        choice = input(operation).strip()
        if choice == '5':
            break
        elif choice == '1':
            view_product_info()
        elif choice == '2':
            balance = purchase(balance, shopping_list)
        elif choice == '3':
            purchasing_list(shopping_list)
        elif choice == '4':
            if balance > 0:
                print("View balance")
                print(f"Your current balance is:{float('%.2f' % balance)}")
        else:
            print("Input error, please re-enter")

    # Print small ticket
    print(f"{'Welcome to Sanle supermarket':^35}")
    print("=" * 40)
    print(f"{'Item number':<7}{'Trade name':<10}{'Unit Price':<5}{'quantity':<5}{'Total price':<5}")
    for item in shopping_list:
        print(f"{item:<10}{goods[item]['name']:<5}{goods[item]['price']:>9}"
              f"{shopping_list[item]:>5}"
              f"{float('%.2f' % (shopping_list[item] * goods[item]['price'])):>7}")
    print(f"Account balance:{float('%.2f' % balance)}")
    print("=" * 40)
    print(f"{'Thank you for your patronage,looking forward to your next visit':^35}")
    print(f"{'Please keep your ticket':^35}")


if __name__ == "__main__":
    menu()

summary

In fact, the function of this shopping system is still relatively simple. It is suitable for beginners. MySQL and crawlers have not been quoted, and it is only written using functions. Therefore, the second version of the shopping system will be released later. Please look forward to it

At that time, it was very difficult to write the function yourself. I hope you don't worry. Take your time and realize the function one by one. When you finish typing all the code, you will feel: Wow, amazing!!!
Come on.

If you have any questions in the process of writing, you can comment or send me a private letter. You will reply when you have time!
If you think this article is helpful, please point a praise * * before you go, thank you****

Topics: Python Functional Programming