Raj has ordered two electronic items Python | Assignment Expert

Problem Statement:

Raj has bought two electronic items x and y with two years of warranty each. But the items didn’t work properly after a few days of use. And hence, Raj decided to return them. The shop has its own refund policy, stated as follows:
i. If the customer is returning an item within a time span of 30 days (inclusive), then he will get a full refund.
ii. If the returning date exceeds 30 days from the date of purchase, then for each day, Rs. 270 will be deducted from the purchased amount.

Given, an input consisting of:
i. x, y: two spaced integers – the price of item1 and item 2
ii. dx_purchased, dy_purchased: two spaced string with the format as (yyyy-mm-dd) -> date of purchasing for x and y
iii. dx_return, dy_return : two spaced string with format as (yyyy-mm-dd) -> date of returning for x and y

Write a Python script, which outputs the refund amount of item x and item y.

Example:
Input:
Enter prices of x and y: 33000 65000
Enter the date of purchase for x and y: 2022-05-31 2022-07-15
Enter the date of the return for x and y: 2022-06-30 2022-09-30
Output:
Refund price of x: 33000
Refund price of y: 52310

Code:

from datetime import datetime
from datetime import timedelta
from operator import truediv


'''convert date string to date object'''
def stringToDate(date_string):
    date_obj = datetime.strptime(date_string, '%Y-%m-%d')
    return date_obj.date()

'''check if the return date is withing 30 days'''
def check30Days(d_purchased,d_return):
    if(d_return <= (d_purchased + timedelta(days=30))):
        return True
    return False

'''calculate the refund amount'''
def calculate_refund(d_purchased,d_return,price):
    d_purchased = stringToDate(d_purchased)
    d_return = stringToDate(d_return)

    if(check30Days(d_purchased,d_return)):
        return price
    else:
        #calculate refund amount from the 31st day from the date of purchased
        d_purchased= d_purchased + timedelta(days=30)
        days = (d_return - d_purchased).days
        return price - (days*270)
        
    
    
'''take input'''
x,y=map(int,input("Enter prices of x and y: ").split(" "))
dx_purchased,dy_purchased = map(str,input("Enter the date of puchased for x and y: ").split(" "))
dx_return, dy_return = map(str,input("Enter the date of return for x and y: ").split(" "))


'''print the results'''
print("Refund price of x: ",calculate_refund(dx_purchased,dx_return,x))
print("Refund price of y: ",calculate_refund(dy_purchased,dy_return,y))

Input:

Raj has ordered two electronic items Python | Assignment Expert Raj has bought two electronic items x and y with two years of warranty each. But the items didn't work properly after a few days of use. And hence, Raj decided to return them. The shop has its own refund policy, stated as follows:i. If the customer is returning an item within a time span of 30 days (inclusive), then he will get a full refund.ii. If the returning date exceeds 30 days from the date of purchase, then for each day, Rs. 270 will be deducted from the purchased amount.

Output:

Raj has ordered two electronic items Python | Assignment Expert Raj has bought two electronic items x and y with two years of warranty each. But the items didn't work properly after a few days of use. And hence, Raj decided to return them. The shop has its own refund policy, stated as follows:i. If the customer is returning an item within a time span of 30 days (inclusive), then he will get a full refund.ii. If the returning date exceeds 30 days from the date of purchase, then for each day, Rs. 270 will be deducted from the purchased amount.

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@violet-cat-415996.hostingersite.com Thank you