-
Notifications
You must be signed in to change notification settings - Fork 44
Description
Objective:
The objective of this assignment is to develop a billing system that reads product details from a file, allows users to input purchase details, and generates a bill that is saved to a file. You will demonstrate your ability to perform file handling operations such as reading, writing, and appending data in Python.
Problem Statement:
You are required to create a Python program that performs the following tasks:
-
Read Product Details:
- Read product details from a text file named
products.txt
. Each line in the file contains information about a product in the format:product_id,product_name,price
. - Example content of
products.txt
:101,Apple,0.5 102,Banana,0.3 103,Orange,0.8 104,Milk,1.2 105,Bread,2.0
- Read product details from a text file named
-
Input Purchase Details:
- Allow the user to input the product ID and quantity for each item they want to purchase. Continue taking inputs until the user decides to stop.
-
Generate Bill:
- Calculate the total cost for each item and the overall total bill.
- Display the bill on the console and save it to a text file named
bill.txt
in the following format:BILL SUMMARY ----------------------------------- Product ID: 101, Product Name: Apple, Quantity: 2, Unit Price: 0.5, Total: 1.0 Product ID: 103, Product Name: Orange, Quantity: 1, Unit Price: 0.8, Total: 0.8 ----------------------------------- Total Bill: 1.8
-
Exception Handling:
- Ensure proper exception handling for scenarios such as file not found, invalid product ID, and invalid input data.
Requirements:
- Use appropriate file handling methods for reading, writing, and appending data.
- Handle potential exceptions that might occur during file operations.
- Ensure the code is well-documented with comments explaining each step.
Submission:
Submit the Python script file named billing_system.py
containing your solution, along with the products.txt
file used for testing.
Example:
Below is an example of how the products.txt
file should look:
101,Apple,0.5
102,Banana,0.3
103,Orange,0.8
104,Milk,1.2
105,Bread,2.0
An example of the output in the bill.txt
file after running the program could look like this:
BILL SUMMARY
-----------------------------------
Product ID: 101, Product Name: Apple, Quantity: 2, Unit Price: 0.5, Total: 1.0
Product ID: 103, Product Name: Orange, Quantity: 1, Unit Price: 0.8, Total: 0.8
-----------------------------------
Total Bill: 1.8
This assignment will help you practice file handling operations and develop a functional billing system in Python. Good luck!