-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapitolo6.py
53 lines (46 loc) · 1.03 KB
/
capitolo6.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import math
def compara(x, y):
if x > y:
return 1
elif x == y:
return 0
else:
return -1
def ipotenusa(cateto1, cateto2):
quadrato1 = cateto1**2
quadrato2 = cateto2**2
return round(math.sqrt(quadrato1 + quadrato2), 2)
def compreso_tra(x, y, z):
if x <= y <= z:
return True
else:
return False
def fattoriale(n):
if not isinstance(n, int):
print('Il fattoriale è definito solo per numeri interi.')
return None
elif n < 0:
print('Il fattoriale non è definito per interi negativi.')
return None
elif n == 0:
return 1
else:
return n * fattoriale(n - 1) # type: ignore
def divisibile(x, y):
if x % y == 0:
return True
else:
return False
def potenza(a, b):
if a == b:
return True
elif divisibile(a, b):
return potenza(a/b, b)
else:
return False
def length(lista):
n = 0
while lista != []:
del lista[0]
n += 1
return n