PDA Assignments
  • Python For Data Analytics
    • 1.Python
      • 1.Python Documents
        • 1.Data Types
        • 2.Variables In Python
        • 3.Operators In Python
        • 4.User Input In Python
        • 5.TypeCasting In Python
        • 6.Strings In Python
        • 7.Conditional Statements In Python
        • 8.Branching using Conditional Statements and Loops in Python
        • 9.Lists In Python
        • 10.Sets In Python
        • 11.Tuples In Python
        • 12.Dictionary In Python
        • 13.Functions In Python
        • 14.File Handling In Python
        • 15.Numerical Computing with Python and Numpy
      • 2.Python Assignments
        • Data Type & Variables
        • Operators Assignment
        • User Input & Type Casting
        • Functions- Basic Assignments
        • String Assignments
          • String CheatSheet
        • Conditional Statements Assignments
        • Loops Assignments
        • List Assignments
          • List Cheatsheet
        • Set Assignments
          • Sets Cheatsheet
        • Dictionary Assignments
          • Dictionary Cheatsheet
        • Function Assignments
        • Functions used in Python
      • 3.Python Projects
        • Employee Management System
        • Hamming distance
        • Webscraping With Python
          • Introduction To Web Scraping
          • Importing Necessary Libraries
          • Basic Introduction To HTML
          • Introduction To BeautifulSoup
          • Flipkart Web Scraping
            • Scraping Step By Step
        • Retail Sales Analysis
        • Guess the Word Game
        • Data Collection Through APIs
        • To-Do List Manager
        • Atm-functionalities(nested if)
        • Distribution of Cards(List & Nested for)
        • Guess the Number Game
      • 4.Python + SQL Projects
        • Bookstore Management System
    • 2.Data Analytics
      • 1.Pandas
        • 1.Pandas Documents
          • 1.Introduction To Pandas
          • Reading and Loading Different Data
          • 2.Indexing and Slicing In Pandas
          • 3.Joining In Pandas
          • 4.Missing Values In Pandas
          • 5.Outliers In Pandas
          • 6.Aggregating Data
          • 7.DateTime In Pandas
          • 8.Validation In Pandas
          • 9.Fetching Data From SQL
          • 10. Automation In Pandas
          • 11.Matplotlib - Data Visualization
          • 12. Seaborn - Data Visualization
          • 13. Required Files
        • 3.Pandas Projects
          • Retail Sales Analysis
            • Retail Sales Step By Step
          • IMDB - Dataset Analysis - Basic
        • 2. Pandas Assignments
          • 1. Reading and Loading the Data
          • 2. Data frame Functions and Properties
          • 3. Series - Basic Operations
          • 4. Filtering in Pandas
          • 5. Advance Filtering
          • 6. Aggregate Functions & Groupby
          • 7. Pivot Tables
          • 8. Datetime
          • 9. String Functions
Powered by GitBook
On this page
  • Scenario
  • Instructions
  1. Python For Data Analytics
  2. 1.Python
  3. 3.Python Projects

Retail Sales Analysis

Scenario

You work for a small cafe that sells various types of coffee, tea, and pastries. The owner has asked you to create a program that helps them keep track of their inventory and sales. The owner wants to be able to add new items to the menu, update the quantities of existing items, and see a summary of the total sales for each item at the end of the day.

Instructions

Write a Python program that allows the cafe owner to perform the following actions:

  1. Add new items to the menu: The program should ask the user to enter the name, category, price, and quantity of a new item. The program should then add the item to a menu list.

  2. Update the quantities of existing items: The program should display a table of all the items in the menu list with their corresponding quantities. The user should be prompted to enter the name of the item they want to update and the new quantity. The program should then update the quantity of the specified item.

  3. View the summary of total sales for each item: The program should display a table of all the items in the menu list with their corresponding quantities and total sales. The total sales should be calculated as the product of the price and quantity of each item sold during the day.

  4. Sales Analysis at the end price wise : At the end, through program one should be able to see the sales price in descending order means item with highest sale should be the first item to be seen in the list.

Welcome to the cafe inventory and sales tracker!

What would you like to do?

  1. Add new item to menu

  2. Update item quantities

  3. View sales summary

  4. Quit

Enter your choice (1-4): 1

Welcome to the cafe inventory and sales tracker!

What would you like to do?

  1. Add new item to menu

  2. Update item quantities

  3. View sales summary

  4. Quit

Enter your choice (1-4): 1

Enter the name of the item: Coffee Enter the category of the item: Beverages Enter the price of the item: 2.50 Enter the quantity of the item: 10

Item added to menu: Name: Coffee Category: Beverages Price: $2.50 Quantity: 10

Enter the name of the item you want to update: Coffee Enter the new quantity: 5

Item quantity updated:

Name: Coffee

New quantity: 5

Name
Category
Price
Quantity
Total Sales

Coffee

Beverages

2.50

10

25

Pizza

Main Dishes

10.99

15

164.85

Salad

Appetizers

5.99

8

47.92

Item Sales : Pizza : 164.85 Salad : 47.92 Coffee : 25.0

Solution
# Define menu list
menu = []

# Define function to add new item to menu
def add_item():
    # Prompt user for item details
    name = input("Enter the name of the item: ")
    category = input("Enter the category of the item: ")
    price = float(input("Enter the price of the item: "))
    quantity = int(input("Enter the quantity of the item: "))
    
    # Add item to menu list
    menu.append({
        "name": name,
        "category": category,
        "price": price,
        "quantity": quantity
    })
    
    # Print confirmation message
    print("Item added to menu:")
    print("Name:", name)
    print("Category:", category)
    print("Price: ${:.2f}".format(price))
    print("Quantity:", quantity)

# Define function to update item quantities
def update_quantity():
    # Print current menu
    print("Current menu:")
    print("Name\tCategory\tPrice\tQuantity")
    for item in menu:
        print(f"{item['name']}\t{item['category']}\t${item['price']}\t{item['quantity']}")
    
    # Prompt user for item to update and new quantity
    name = input("Enter the name of the item you want to update: ")
    quantity = int(input("Enter the new quantity: "))
    
    # Update quantity of specified item
    for item in menu:
        if item["name"] == name:
            item["quantity"] = quantity
            # Print confirmation message
            print("Item quantity updated:")
            print("Name:", name)
            print("New quantity:", quantity)
            return
    
    # Print error message if item not found
    print("Error: Item not found in menu")

# Define function to view sales summary
def view_summary():
    # Print sales summary
    print("Sales summary:")
    print("Name\tCategory\tPrice\tQuantity\tTotal sales")
    for item in menu:
        total_sales = item["price"] * item["quantity"]
        print(f"{item['name']}\t{item['category']}\t${item['price']}\t{item['quantity']}\t${total_sales}")

#To get the sales total sales wise from top to bottom
def get_top():
    sales = []
    for item in menu:
        sales.append((item['name'], item["price"]*item["quantity"]))
    print('Item Sales : ')
    sales.sort(key = lambda a:a[-1], reverse = True)
    for name, value in sales:
        print(f'{name} : {value}')

# Main program loop
while True:
    # Print menu
    print()
    print("\nWelcome to the cafe inventory and sales tracker!\n")
    print("What would you like to do?")
    print("1. Add new item to menu")
    print("2. Update item quantities")
    print("3. View sales summary")
    print("4. View Sales Analysis")
    print("5. Quit")
    
    # Prompt user for choice
    choice = input("\nEnter your choice (1-4): ")
    
    # Perform action based on user choice
    if choice == "1":
        add_item()
    elif choice == "2":
        update_quantity()
    elif choice == "3":
        view_summary()
    elif choice == "4":
        get_top()
    elif choice == "5":
        print("\nGoodbye!")
        break
    else:
        print("Error: Invalid choice")
PreviousScraping Step By StepNextGuess the Word Game

Last updated 2 years ago