Python function that will calculate the GST

In this tutorial, we will learn  how to calculate GST using python programming , it is a goods and service tax. It is applicable in India  and it is paid by the customers to the government  inorder to make gst calculation easy . Here this tutorial is created to know how much tax  you are paying for a product.

To calculate the GST, first, compute the net GST amount by subtracting the original price from the net price that includes the GST. We use GST percent formula after calculating the net gst amount.

GST% formula = ((GST Amount * 100)/Original price)

Net price        = Original price + GST amount

GST amount   = Net price – Original price

GST%             = ((GST amount * 100)/Original price)

round() function: round function rounds off to the nearest integer value.

We have the Net price, the original price, and the task is to calculate the GST percentage,

Input:  Given original price = 520
        Given Net price       = 650
Output: The GST percent for the above given input net and original prices =  25.0%

Program to calculate GST

There are two ways to Calculate GST.

Method 1: Using Mathematical Formula (Static input)

  • We define the calculate_gst function as before.
  • We then provide static values for original_price and gst_rate.
  • We call the calculate_gst function with these static values.

Finally, we print out the original price, GST amount, and total price including GST.

def calculate_gst(original_price, gst_rate):
    gst_amount = original_price * (gst_rate / 100)
    total_price = original_price + gst_amount
    return gst_amount, total_price


original_price = 1000  # Example original price
gst_rate = 18  # Example GST rate


gst_amount, total_price = calculate_gst(original_price, gst_rate)

Output:  print(f"Original Price: ${original_price:.2f}")
           print(f"GST Amount: ${gst_amount:.2f}")
           print(f"Total Price (including GST): ${total_price:.2f}")

Method 2: Using Mathematical Formula (User input)

  • We define the calculate_gst function as before.
  • We prompt the user to enter the original price and GST rate using the input function.
  • We convert the user inputs to floating-point numbers using float.
  • We call the calculate_gst function with the user-provided values.
  • Finally, we print out the original price, GST amount, and total price including GST in a single line.

def calculate_gst(original_price, gst_rate):
    gst_amount = original_price * (gst_rate / 100)
    total_price = original_price + gst_amount
    return gst_amount, total_price

original_price = float(input("Enter the original price: "))
gst_rate = float(input("Enter the GST rate (%): "))


gst_amount, total_price = calculate_gst(original_price, gst_rate)
Output:
print (f"Original Price: ${original_price:.2f}")
 print(f"GST Amount: ${gst_amount:.2f}")
print(f"Total Price (including GST): ${total_price:.2f}")

Leave a Comment

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

Scroll to Top