Created
July 7, 2020 05:29
-
-
Save abhi923/df2f9e898570faab51998a1b68a8b4fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def isYearLeap(year): | |
if (year % 4) == 0: | |
if (year % 100) == 0: | |
if (year % 400) == 0: | |
return True | |
else: | |
return False | |
else: | |
return True | |
else: | |
return False | |
# Return true if year is a multiple | |
# of 4 and not multiple of 100. | |
# OR year is multiple of 400. | |
# return (((year % 4 == 0) and (year % 100 != 0)) or (year % 400 == 0)); | |
testData = [1900, 2000, 2015, 1987] | |
testResults = [False, True, True, False] | |
for i in range(len(testData)): | |
yr = testData[i] | |
print(yr, "->", end="") | |
result = isYearLeap(yr) | |
if result == testResults[i]: | |
print("OK - Leap Year") | |
else: | |
print("Failed - Not Leap Year") | |
# ------------------------- x ------------------------ x ----------------- | |
def isYearLeap(year): | |
return (((year % 4 == 0) and (year % 100 != 0)) or (year % 400 == 0)); | |
days_month_normal = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] | |
days_month_leapyr = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] | |
def daysInMonth(year, month): | |
if isYearLeap(year): | |
return days_month_leapyr[month] | |
return days_month_normal[month] | |
testYears = [1900, 2000, 2016, 1987] | |
testMonths = [2, 2, 5, 11] | |
testResults = [28, 29, 31, 30] | |
for i in range(len(testYears)): | |
yr = testYears[i] | |
mo = testMonths[i] | |
print(yr, mo, "->", end="") | |
result = daysInMonth(yr, mo) | |
if result == testResults[i]: | |
print("OK") | |
else: | |
print("Failed") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh encontre lo que buscaba , gracias :)