I have the following codes:
JavaScript
x
5
1
if date in (start, end):
2
print('in between')
3
else:
4
print('No!')
5
date, start and end are all variables with the format of 1/1. What should I do to have it print out the right result? i tried date as 10/2, start as 3/14 and end as 11/7 and it’s print ‘No!’, which means it’s not running right. I guess have to format them to a date format and then compare them.
Advertisement
Answer
As you are still not satisfied, I have another answer for you. Without using datetime and year.
It just uses built-in tuples and comparing them:
JavaScript
1
8
1
d1 = (3, 28)
2
d2 = (3, 31)
3
d3 = (4, 2)
4
if d1 < d2 < d3:
5
print("BETWEEN!")
6
else:
7
print("NOT!")
8
You can create tuple like these easily:
JavaScript
1
4
1
day = 16
2
month = 4
3
d = (month, day)
4