Python program to calculate GST Goods and Service Tax

To calculate the Goods and Services Tax (GST) in Python, you need to consider the following:

  1. GST Rates: Different products/services might have different GST rates.
  2. Original Price: The base price of the product/service before GST is applied.
  3. Total Price: The final price after adding GST.

The formula to calculate GST is:

GST Amount=Original Price×(GST Rate/100)

The total price including GST is:

Total Price=Original Price+GST Amount

def calculate_gst(original_price, gst_rate):
    # Calculate GST amount
    gst_amount = original_price * (gst_rate / 100)
    
    # Calculate total price
    total_price = original_price + gst_amount
    
    return gst_amount, total_price

def main():
    # Input original price
    original_price = float(input("Enter the original price: "))
    
    # Input GST rate
    gst_rate = float(input("Enter the GST rate (in percentage): "))
    
    # Calculate GST and total price
    gst_amount, total_price = calculate_gst(original_price, gst_rate)
    
    # Print the results
    print(f"GST Amount: {gst_amount:.2f}")
    print(f"Total Price after GST: {total_price:.2f}")

if __name__ == "__main__":
    main()
Output : 

Enter the original price: 1000
Enter the GST rate (in percentage): 18
GST Amount: 180.00
Total Price after GST: 1180.00

Explanation

  1. Function calculate_gst:
    • Takes the original_price and gst_rate as arguments.
    • Calculates the GST amount.
    • Calculates the total price including GST.
    • Returns the GST amount and the total price.
  2. Function main:
    • Prompts the user to enter the original price and GST rate.
    • Calls calculate_gst with these values.
    • Prints the GST amount and the total price formatted to two decimal places.

Leave a Reply

Your email address will not be published. Required fields are marked *