Compare commits

...
3 Commits
Author SHA1 Message Date
davide 752b04b4fe aggiunge esercizio 26 2026-04-08 18:09:57 +02:00
davide f35db81e06 aggiunge esercizio 25 2026-04-08 17:56:49 +02:00
davide 722a209308 aggiunge esercizio 24 2026-04-08 17:38:47 +02:00
3 changed files with 84 additions and 0 deletions
+31
View File
@@ -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")
+35
View File
@@ -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))
+18
View File
@@ -0,0 +1,18 @@
def is_prime(num):
div = []
if num is float:
return None
for i in range(1,num+1):
if num % i == 0:
div.append(i)
if len(div) == 2:
return num
for i in range(1,20):
if is_prime(i+1):
print(i+1,end=" ")
print()