Write A Python Program To Input Quantity and price from user And Calculate Discount And Bill Amount After Discount

In this blog post, we will write a Python program to input quantity and price from the user and calculate discount and bill amount after discount. This program is useful for calculating the total bill amount for a purchase, taking into account any discounts that may be available.

Prerequisites:

To follow this blog post, you should have a basic understanding of Python programming. If you are new to Python, you can learn more about it from the following resources:

  • Python Tutorial: https://docs.python.org/3/tutorial/
  • Learn Python: https://www.codecademy.com/catalog/language/python

Program:

The following Python program inputs quantity and price from the user and calculates discount and bill amount after discount:

Python
# Input quantity and price from the user
quantity = int(input("Enter quantity: "))
price = float(input("Enter price: "))

# Calculate discount amount
discount = 0
bill_amount = quantity * price
if bill_amount > 1000:
    discount = bill_amount * 0.1
elif bill_amount > 500:
    discount = bill_amount * 0.05

# Calculate bill amount after discount
bill_amount_after_discount = bill_amount - discount

# Print the results
print("Bill amount: ", bill_amount)
print("Discount amount: ", discount)
print("Bill amount after discount: ", bill_amount_after_discount)

Example:

Python
Enter quantity: 10
Enter price: 100

Bill amount: 1000.0
Discount amount: 100.0
Bill amount after discount: 900.0

Unique Features:

The following are some unique features of this Python program:

  • The program calculates discount based on the total bill amount, which is more realistic than calculating discount based on the price of an individual item.
  • The program is flexible and can be easily modified to support different discount slabs.
  • The program is easy to understand and use, even for beginners.

Applications:

This Python program can be used in a variety of applications, such as:

  • Calculating the total bill amount for a purchase in a retail store
  • Calculating the total bill amount for a meal in a restaurant
  • Calculating the total bill amount for a taxi ride
  • Calculating the total bill amount for a hotel stay

Conclusion:

This Python program is a useful tool for calculating discount and bill amount after discount. It is easy to understand and use, and it can be used in a variety of applications.

Additional Information:

In addition to the above, here is some additional information about calculating discount and bill amount after discount in Python:

  • Different types of discounts: There are different types of discounts that can be applied to a purchase, such as:

    • Percentage discount: This is a discount that is calculated as a percentage of the total bill amount.
    • Fixed amount discount: This is a discount that is a fixed amount, regardless of the total bill amount.
    • Slab discount: This is a discount that is applied based on different slabs of the total bill amount. For example, a slab discount may be applied as follows:
      • 10% discount on the first $100 of the bill amount
      • 20% discount on the next $200 of the bill amount
      • 30% discount on the remaining bill amount
  • Calculating discount: To calculate discount, we can use the following formula:

Discount = (Discount rate * Total bill amount) / 100
  • Calculating bill amount after discount: To calculate bill amount after discount, we can use the following formula:
Bill amount after discount = Total bill amount - Discount

Example:

Suppose we have a purchase with a total bill amount of $1000 and we want to apply a 10% discount. To calculate the discount amount, we can use the following formula:

Discount = (10 * 1000) / 100
Discount = $100

To calculate the bill amount after discount, we can use the following formula:

Bill amount after discount = 1000 - 100
Bill amount after discount = $900
 

Different types of discounts:

In addition to the types of discounts mentioned earlier, there are a few other types of discounts that are commonly used:

  • Seasonal discount: This is a discount that is offered during a specific season, such as a winter sale or a summer sale.
  • Promotional discount: This is a discount that is offered to promote a particular product or service.
  • Loyalty discount: This is a discount that is offered to customers who have been loyal to a business for a certain period of time.

Calculating discount for multiple items:

If we have a purchase with multiple items, we can calculate the discount for each item separately and then add up the discount amounts. Alternatively, we can calculate the total bill amount for the purchase and then apply the discount to the total bill amount.

For example, suppose we have a purchase with two items:

  • Item 1: Price = $100, Quantity = 1
  • Item 2: Price = $50, Quantity = 2

If we want to apply a 10% discount to each item, we can calculate the discount for each item separately as follows:

Discount for item 1 = (10 * 100) / 100 = $10
Discount for item 2 = (10 * 50 * 2) / 100 = $10

The total discount amount for the purchase is $20.

If we want to calculate the discount for the total bill amount, we can first calculate the total bill amount as follows:

Total bill amount = (100 * 1) + (50 * 2) = $200

Then, we can apply the 10% discount to the total bill amount as follows:

Discount = (10 * 200) / 100 = $20

The total discount amount for the purchase is $20, which is the same as the discount amount that we calculated earlier when we calculated the discount for each item separately.

Using the Python program in different applications:

The Python program that we wrote earlier can be used in a variety of applications, such as:

  • Calculating the total bill amount for a purchase in a retail store: The program can be used to calculate the total bill amount for a purchase in a retail store, taking into account any discounts that may be available.
  • Calculating the total bill amount for a meal in a restaurant: The program can be used to calculate the total bill amount for a meal in a restaurant, taking into account any discounts that may be available, such as early bird specials or happy hour specials.
  • Calculating the total bill amount for a taxi ride: The program can be used to calculate the total bill amount for a taxi ride, taking into account any discounts that may be available, such as distance discounts or time discounts.
  • Calculating the total bill amount for a hotel stay: The program can be used to calculate the total bill amount for a hotel stay, taking into account any discounts that may be available, such as weekday discounts or weekend discounts.

Conclusion:

This Python program is a useful tool for calculating discount and bill amount after discount. It is easy to understand and use, and it can be used in a variety of applications.

 

Post a Comment

0 Comments