Pankaj-Str / Complete-Python-Mastery

Explore the world of Python programming with 'Complete Python Mastery'! Our repository, led by Pankaj, offers a series of in-depth tutorials under the banner 'Codes with Pankaj.' Dive into hands-on coding examples, insightful explanations, and practical projects as Pankaj guides you through mastering Python.
https://www.codeswithpankaj.com/
32 stars 25 forks source link

Assignment: Billing System Using File Handling in Python #6

Open Pankaj-Str opened 3 months ago

Pankaj-Str commented 3 months ago

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:

  1. 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
  2. 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.
  3. 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
  4. Exception Handling:

    • Ensure proper exception handling for scenarios such as file not found, invalid product ID, and invalid input data.

Requirements:

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!