Professional Documents
Culture Documents
CsArt (1) - Combined - Organized
CsArt (1) - Combined - Organized
def get_total_price(self):
return self.price * self.quantity
def get_gst_amount(self):
return (self.price * self.quantity) * (self.gst_rate / 100)
def get_total_amount(self):
return self.get_total_price() + self.get_gst_amount()
class BillingSoftware:
def __init__(self):
self.products = []
def calculate_total_amount(self):
total_amount = 0
for product in self.products:
total_amount += product.get_total_amount()
return total_amount
def generate_bill(self):
print("********** Invoice **********")
for product in self.products:
print(f"Name: {product.name}")
print(f"Price: {product.price}")
print(f"Quantity: {product.quantity}")
print(f"GST Rate: {product.gst_rate}")
print(f"Total Price: {product.get_total_price()}")
print(f"GST Amount: {product.get_gst_amount()}")
print(f"Total Amount (incl. GST): {product.get_total_amount()}")
print("-----------------------------")
print(f"Total Amount to be paid: {self.calculate_total_amount()}")
def clear_bill(self):
self.products = []
if __name__ == "__main__":
Operation of code (used with an indentation):
# Creating instance of the billing software
billing = BillingSoftware()
1) This code under the ‘if’ statement (with an
indentation) is used to create instance for the
software.
# Adding products
billing.add_product(Product("Product name", Price, Quantity, GST rate))
2) This code is used to add products with its name, price,
quantity and GST rate accordingly. Multiple of it can
be written to add multiple products.
# Generating bill
billing.generate_bill()
3) This line of code is used to generate the processed bill.
Output: