To calculate the Goods and Services Tax (GST) in Python, you need to consider the following:
- GST Rates: Different products/services might have different GST rates.
- Original Price: The base price of the product/service before GST is applied.
- 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
- Function
calculate_gst
:- Takes the
original_price
andgst_rate
as arguments. - Calculates the GST amount.
- Calculates the total price including GST.
- Returns the GST amount and the total price.
- Takes the
- 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.