-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7 kyu The Coupon Code
28 lines (22 loc) · 1008 Bytes
/
7 kyu The Coupon Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
https://www.codewars.com/
Story
Your online store likes to give out coupons for special occasions. Some customers try to cheat the system by entering invalid codes or using expired coupons.
Task
Your mission:
Write a function called checkCoupon which verifies that a coupon code is valid and not expired.
A coupon is no more valid on the day AFTER the expiration date. All dates will be passed as strings in this format: "MONTH DATE, YEAR".
Examples:
checkCoupon("123", "123", "July 9, 2015", "July 9, 2015") == True
checkCoupon("123", "123", "July 9, 2015", "July 2, 2015") == False
"""
from datetime import datetime as dt
def check_coupon(entered_code, correct_code, current_date, expiration_date):
current, expire = dt.strptime(current_date, '%B %d, %Y'), dt.strptime(expiration_date, '%B %d, %Y')
if (entered_code == correct_code) and (expire >= current):
if correct_code == False:
return False
else:
return True
else:
return False