-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmp copy 2.py
More file actions
61 lines (45 loc) · 1.14 KB
/
Copy pathtmp copy 2.py
File metadata and controls
61 lines (45 loc) · 1.14 KB
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
54
55
56
57
58
59
60
61
import time
def file(filname):
with open(filname, "r") as f:
for line in f:
yield line
z = file("requirements.txt")
print("-------------------- CONTENUTO FILE --------------------")
while True:
try:
print(next(z), end="")
except MemoryError:
print("errore di memoria")
except StopIteration:
break
print("---------------------- FINE FILE ----------------------")
va = 800
def fattoriale (n):
if n == 0:
return 1
else:
return n * fattoriale(n-1)
t1= time.time()
f1 = 0
try:
f1 = fattoriale(va)
except RecursionError:
print("non ce la si fa")
t2= time.time()
print(f"""risultato: {f1} con tempo di: {t2-t1}""")
def fattoriale_rec(n, res):
if n == 0:
return res
else:
return fattoriale_rec(n-1, n*res)
def fattoriale (n):
if n == 0:
return 1
else:
return fattoriale_rec(n - 1, n)
print(fattoriale(3))
t3= time.time()
f1 = fattoriale(va)
t4= time.time()
print(f"""risultato: {f1} con tempo di: {t2-t1}""")
print(f"""\n\n{(t2-t1) < (t4-t3)} | {(t4-t3) - (t2-t1)}""")