aggiunge esercizio 25
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
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]
|
||||||
|
|
||||||
|
def day_of_year(year, month, day):
|
||||||
|
if month < 1 or month > 12:
|
||||||
|
return None
|
||||||
|
elif day < 1 or day > 31:
|
||||||
|
return None
|
||||||
|
elif day > 29 and is_year_leap(year) == True and month == 2:
|
||||||
|
return None
|
||||||
|
elif day > 28 and is_year_leap(year) == False and month == 2:
|
||||||
|
return None
|
||||||
|
|
||||||
|
day_ = day
|
||||||
|
|
||||||
|
for i in range(1,month):
|
||||||
|
mo = days_in_month(year,i)
|
||||||
|
day_ += mo
|
||||||
|
|
||||||
|
return day_
|
||||||
|
|
||||||
|
print(day_of_year(2001,2,29))
|
||||||
|
|
||||||
Reference in New Issue
Block a user