aggiunge esercizio 24
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
# from lab23 import is_year_leap
|
||||
|
||||
def is_year_leap(year):
|
||||
if year % 4 == 0:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def days_in_month(year, month):
|
||||
|
||||
days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
||||
|
||||
if is_year_leap(year) == True:
|
||||
days[1] = 29
|
||||
|
||||
return days[month - 1]
|
||||
|
||||
test_years = [1901, 2000, 2016, 1987]
|
||||
test_months = [2, 2, 1, 11]
|
||||
test_results = [28, 29, 31, 30]
|
||||
|
||||
for i in range(len(test_years)):
|
||||
yr = test_years[i]
|
||||
mo = test_months[i]
|
||||
|
||||
print(yr, mo, "->", end="")
|
||||
result = days_in_month(yr, mo)
|
||||
if result == test_results[i]:
|
||||
print("OK")
|
||||
else:
|
||||
print("Failed")
|
||||
Reference in New Issue
Block a user