forked from Rishi098/Advance_Python_Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDate-Validation-Algorithm.py
More file actions
23 lines (18 loc) · 940 Bytes
/
Copy pathDate-Validation-Algorithm.py
File metadata and controls
23 lines (18 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Write a function named “isTheDateValid” that accepts three integers as parameters (yyyy, mm, dd); the first one is year,
# second for month number and third for day of the month and return True or False
# depending upon whether the given argument values represent a valid date or not and
# returns True or False.
# Following are examples calls and their expected results;
# isTheDateValid(2023, 5, 8) returns True,
# While calling it as isTheDateValid(2023,2,29) returns False
# And isTheDateValid(2020, 2, 29) returns True
def isTheDateValid(yyyy, mm, dd):
if yyyy > 2000 and (mm == 1 or mm == 3 or mm == 5 or mm == 7 or mm == 8 or mm == 10 or mm == 12) and dd <= 31:
print("true")
elif yyyy > 2000 and (mm == 4 or mm == 6 or mm == 9 or mm == 11) and dd <= 30:
print("true")
elif yyyy > 2000 and mm == 2 and dd <= 28:
print("true")
else:
print("false")
isTheDateValid(2004, 3, 29)