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:
Output:
Also Read:
- Hyphenate Letters in Python
- Earthquake in Python | Easy Calculation
- Striped Rectangle in Python
- Perpendicular Words in Python
- Free shipping in Python
- Raj has ordered two electronic items Python | Assignment Expert
- Team Points in Python
- Ticket selling in Cricket Stadium using Python | Assignment Expert
- Split the sentence in Python
- String Slicing in JavaScript
- First and Last Digits in Python | Assignment Expert
- List Indexing in Python
- Date Format in Python | Assignment Expert
- New Year Countdown in Python
- Add Two Polynomials in Python
- Sum of even numbers in Python | Assignment Expert
- Evens and Odds in Python
- A Game of Letters in Python
- Sum of non-primes in Python
- Smallest Missing Number in Python
- String Rotation in Python
- Secret Message in Python
- Word Mix in Python
- Single Digit Number in Python
- Shift Numbers in Python | Assignment Expert
- Weekend in Python
- Shift Numbers in Python | Assignment Expert
- Temperature Conversion in Python
- Special Characters in Python
- Sum of Prime Numbers in the Input in Python