Free shipping in Python

Problem Statement:

There’s a big festival sale running on an e-commerce website. There are certain conditions for shipping charges and under the sale and there are a lot of discounts as well. Design a program that calculates the final cart values i.e. prices after the discount and shipping charges from the given prices of the cart.

Discounts are based on the following criteria:

i. For the cart rate less than 299, no discount will be applicable.
ii. For the cart rate between 299 and 699 (both inclusive), a 12% discount will be applicable.
iii. For the cart rate between 700 and 1599 (both inclusive), a 28% discount will be applicable.
iv. For the cart rate between 1600 and 2499 (both inclusive), a 32% discount will be applicable.
v. For the cart rate equal to and above 2500, a 40% discount will be applicable.

Shipping charges of Rs. 99 will be applicable if the final cart value is under 500. Above and equal to 500 will be eligible for free shipping.
Given the product prices of customers, return the final cart values including discount and shipping.
Also specify, if the customer is applicable for free shipping or not.

Example:
Input:
5
99 389 700 1700 5000
Output:
Order values of Customer 1: 198
Order values of Customer 2: 442
Order values of Customer 3: 504 (Free Shipping)
Order values of Customer 4: 1156 (Free Shipping)
Order values of Customer 5: 3000 (Free Shipping)

Code:

# function to find final cart values
def isFree(cart_values,n):
    results = list()
    for i in range(n):
        if(cart_values[i]>=299 and cart_values[i]<=699):
            results.append(cart_values[i] - (12*cart_values[i])//100)
        elif(cart_values[i]>699 and cart_values[i]<=1599):
            results.append(cart_values[i] - (28*cart_values[i])//100)
        elif(cart_values[i]>1599 and cart_values[i]<=2499):
            results.append(cart_values[i] - (32*cart_values[i])//100)
        elif(cart_values[i]>2499):
            results.append(cart_values[i] - (40*cart_values[i])//100)
        else:
            results.append(cart_values[i])
    
    return results
       
customers = int(input("Enter the no. of customers: "))
cart_values = list(map(int,input("Enter the cart values: ").split()))
results = isFree(cart_values, customers)

#print the result
i=1
for each in results:
    if(each<=499):
        each = each + 99
        print(f"Order values of Customer {i}: {each}")
    else:
        print(f"Order values of Customer {i}: {each} (Free Shipping)")
    i+=1

Input:

Free shipping in Python There's a big festival sale running on an e-commerce website. There are certain conditions for shipping charges and under the sale and there are a lot of discounts as well. Design a program that calculates the final cart values i.e. prices after the discount and shipping charges from the given prices of the cart.

Output:

Free shipping in Python There's a big festival sale running on an e-commerce website. There are certain conditions for shipping charges and under the sale and there are a lot of discounts as well. Design a program that calculates the final cart values i.e. prices after the discount and shipping charges from the given prices of the cart.

Also Read:

Share:

Author: Harry

Hello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at admin@copyassignment.com Thank you