Python Projects

Ecommerce Website Checkout Calculation with Python

PREREQUISITES

To Practice this Program, you should have a basic knowledge of the following Topics:

PYTHON-FUNCTIONSS

INPUT & PRINT FUNCTION

We will use Input & Print Function to collect & print data from the website user into variables.

dt

INTEGER & FLOAT

We will accept the user input in float or integer so that it can be calculated.

python-py

INTEGER/FLOAT CALCULATIONS

We will perform calculations on user input to determine the final result. For eg: +, -, /, * etc.

WHAT TO DO ?

Given,

Potato : 10Rs/Kg , Tomato : 20Rs/Kg , Onion : 30Rs/Kg

Ask User Qty in Kgs for each item above

And Calculate its final bill after 10% discount & 50Rs Delivery Charges.

HOW TO DO ?

Following are the steps to do :

01.

DEFINE VARIABLES AND ASK QUANTITY

At First, We have to define given variables of prices all items and ask quantity for each item.

</p>
<div class="wp-block-codemirror-blocks-code-block code-block">
<pre>potato = 10
tomato = 20 
onion = 30

print("How much qty do you want to purchase for the following items ? ")
potato_qty = int(input("Potato(in Kgs) : "))
tomato_qty = int(input("Tomato(in Kgs) : "))
onion_qty = int(input("Onion(in Kgs) : "))
</pre>
</div>
02.

DETERMINE CART VALUE

Then, We will determine the cart value by calculating each item’s price with quantity.

<div class="wp-block-codemirror-blocks-code-block code-block">
<pre>cart_value = potato * potato_qty + tomato * tomato_qty + onion * onion_qty
print("CART VALUE " + str(cart_value))
</pre>
</div>
03.

FINAL BILL

Finally, We will determine the final bill after discount and delivery charges.

<div class="wp-block-codemirror-blocks-code-block code-block">
<pre>discount = cart_value*0.10
print("Less Discount " + str(discount))
delivery = 50
print("Add Delivery Charges " + str(delivery))
final_bill = cart_value - discount + delivery
print("Your final bill is " + str(final_bill))</pre>
</div>
Things We Covered
  • Accepting User Data (Input Function)
  • Integer/String Conversion (Int/Str Function)
  • Calculations (Arithmetic Operators)

Posted by Akshay Gupta

Leave a Reply

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