0% found this document useful (0 votes)
2 views8 pages

Python Assignment

The document outlines a Python assignment to create a menu-driven Order Management System using nested dictionaries to manage customer orders and products. It specifies required functionalities such as adding, canceling, generating bills, searching, and displaying orders, along with a structured product dictionary and order dictionary format. The program should maintain product stock and retrieve product details dynamically during order processing.

Uploaded by

Anime world
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

Python Assignment

The document outlines a Python assignment to create a menu-driven Order Management System using nested dictionaries to manage customer orders and products. It specifies required functionalities such as adding, canceling, generating bills, searching, and displaying orders, along with a structured product dictionary and order dictionary format. The program should maintain product stock and retrieve product details dynamically during order processing.

Uploaded by

Anime world
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Assignment: Order Management System

Problem Statement

Create a menu-driven Order Management System using Python.

The system should maintain customer orders using a nested dictionary. Products are already
available in a separate products dictionary.

When a customer places an order, the system should display all currently available products with
their Product ID, Product Name, Category, Price, and Stock.

The customer should select products using their Product ID and enter the required quantity.

The order data should be stored in a separate orders dictionary.

Given Product Dictionary

Use the following product dictionary:

products = {

101: {

"pname": "Laptop",

"category": "Electronics",

"price": 55000,

"stock": 10

},

102: {

"pname": "Mouse",

"category": "Electronics",

"price": 800,

"stock": 25

},

103: {

"pname": "Keyboard",

"category": "Electronics",

"price": 1500,

"stock": 15

},
104: {

"pname": "Monitor",

"category": "Electronics",

"price": 12000,

"stock": 8

Create an empty dictionary for storing orders:

orders = {}

Order Dictionary Structure

The Order ID must be used as the key.

For example:

orders = {

5001: {

"customer_name": "Rahul",

"products": {

101: 2,

103: 1

Here:

• 5001 → Order ID

• Rahul → Customer Name

• 101: 2 → Product ID 101, Quantity 2

• 103: 1 → Product ID 103, Quantity 1

Do not store Product Name, Category, or Price inside the order dictionary. These details must be
retrieved from the products dictionary whenever required.

Required Operations
1. Add Order

Create a function add_order().

The function should:

1. Ask the user to enter an Order ID.

2. Check whether the Order ID already exists.

3. Ask for the Customer Name.

4. Display all products that currently have stock greater than zero.

Example:

========================================================

AVAILABLE PRODUCTS

========================================================

ID Name Category Price Stock

--------------------------------------------------------

101 Laptop Electronics 55000 10

102 Mouse Electronics 800 25

103 Keyboard Electronics 1500 15

104 Monitor Electronics 12000 8

========================================================

5. Ask the customer to enter a Product ID.

6. Ask for the required Quantity.

7. Check whether the Product ID exists.

8. Check whether sufficient stock is available.

9. If valid, add the Product ID and Quantity to the order.

10. Ask whether the customer wants to purchase another product.

11. Continue until the customer chooses No.

12. Store the completed order in the orders dictionary.

Example:

Enter Order ID: 5001

Enter Customer Name: Rahul


Enter Product ID: 101

Enter Quantity: 2

Product added successfully.

Do you want to add another product? yes

Enter Product ID: 103

Enter Quantity: 1

Product added successfully.

Do you want to add another product? no

The order should be stored as:

orders[5001] = {

"customer_name": "Rahul",

"products": {

101: 2,

103: 1

Stock Update

After successfully adding a product to an order, reduce the quantity from the product's stock.

Example:

Laptop Stock = 10

Ordered Quantity = 2

New Stock = 8

2. Cancel Order

Create a function cancel_order().


The function should:

1. Ask the user to enter the Order ID.

2. Check whether the order exists.

3. If the order exists, cancel the order.

4. Before deleting the order, restore the purchased quantities back to the product stock.

5. Remove the order from the orders dictionary.

Example:

Enter Order ID: 5001

Order cancelled successfully.

Stock has been restored.

If the Order ID does not exist:

Order not found.

3. Generate Bill

Create a function generate_bill().

The function should:

1. Ask the user to enter the Order ID.

2. Check whether the order exists.

3. Retrieve the customer name and purchased Product IDs from the orders dictionary.

4. Use the Product ID to retrieve the product details from the products dictionary.

5. Get the current product price.

6. Calculate the amount using:

Amount = Quantity × Price

7. Calculate the total bill amount.

8. Display a properly formatted bill.

Example:

================================================

CUSTOMER BILL

================================================
Order ID : 5001

Customer Name : Rahul

------------------------------------------------

Product Qty Price Amount

------------------------------------------------

Laptop 2 55000 110000

Keyboard 1 1500 1500

------------------------------------------------

Total Amount : 111500

================================================

Important

The bill should not take the product price from the order dictionary.

Instead, retrieve it from:

products[product_id]["price"]

4. Search Order

Create a function search_order().

Ask the user for an Order ID and display:

• Order ID

• Customer Name

• Product ID

• Product Name

• Quantity

Example:

Enter Order ID: 5001

Order ID : 5001

Customer Name : Rahul


Products:

--------------------------------

Product ID : 101

Product : Laptop

Quantity : 2

Product ID : 103

Product : Keyboard

Quantity : 1

Product name should be retrieved from the products dictionary.

5. Display All Orders

Create a function display_orders().

Display all stored orders in a readable format.

Example:

================================================

ALL ORDERS

================================================

Order ID Customer Name Products

------------------------------------------------

5001 Rahul 2

5002 Amit 3

5003 Sneha 1

================================================

Main Menu

The program should have the following Order Management menu:

========================================

ORDER MANAGEMENT

========================================
1. Add Order

2. Cancel Order

3. Generate Bill

4. Search Order

5. Display All Orders

6. Back to Main Menu

Enter your choice:

The menu should continue running until the user selects Back to Main Menu.

You might also like