Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

 

python1

import pandas as pd

csv_filename = 'bakery_inventory.csv'

def read_data_from_csv(filename):

    try:

        data = pd.read_csv(filename).set_index("Item")

        return data

    except FileNotFoundError:

        return pd.DataFrame(columns=["Item", "Quantity", "Price"])

def write_data_to_csv(filename, data):

    data.to_csv(filename, index=False)

bakery_data = read_data_from_csv(csv_filename)

available_items = bakery_data.copy()

while True:

    print("\nWelcome to Our Bakery!")

    print("1. Add item to inventory")

    print("2. View inventory status")

    print("3. View available items with price and quantity")

    print("4. Generate invoice")

    print("5. Exit")

    try:

        choice = int(input("Enter your choice (1/2/3/4/5): "))

        if choice == 1:

            item_name = input("Enter the item name: ")

            if item_name not in available_items.index:


                print(f"{item_name} is not an available item.")

            else:

                quantity = int(input("Enter the quantity: "))

                available_items.at[item_name, 'Quantity'] += quantity

                write_data_to_csv(csv_filename, available_items)

                print(f"{quantity} {item_name}(s) added to the inventory.")

        elif choice == 2:

            print("\nInventory Status:")

            print(available_items[['Item', 'Quantity']])

        elif choice == 3:

            print("\nAvailable Items with Price and Quantity:")

            print(available_items[['Item', 'Price', 'Quantity']])

        elif choice == 4:

            print("\nInvoice:")

            total_price = 0

            for _, row in available_items.iterrows():

                item_name = row['Item']

                quantity = row['Quantity']

                price = row['Price']

                item_total = quantity * price

                total_price += item_total

                print(f"{item_name}: {quantity} x {price} = {item_total}")

            print(f"Total Price: {total_price}")

            available_items['Quantity'] = 0  # Empty inventory after generating invoice

            write_data_to_csv(csv_filename, available_items)  # Update inventory after


purchase

        elif choice == 5:

            print("Exiting Bakery Management System. Goodbye!")


            break

        else:

            print("Invalid choice. Please try again.")

    except ValueError:

        print("Invalid input. Please enter a valid option (1/2/3/4/5).")


     

© 2018-2020 dndsofthub All Rights Reserved

You might also like