File tree 1 file changed +43
-0
lines changed
Roadmap/06 - RECURSIVIDAD/python
1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ def countdown (numero : int ):
2
+ if numero >= 0 :
3
+ print (numero )
4
+ countdown (numero - 1 )
5
+
6
+ countdown (5 )
7
+
8
+ # Extra #
9
+
10
+ # Sin recursividad
11
+ def factorial (number : int ) -> int : # Li dic que m'ha de retorna un enter
12
+ calculo = 1
13
+ for i in range (1 ,number + 1 ):
14
+ calculo = i * calculo
15
+ print (f"Este és el primer factorial { calculo } " )
16
+
17
+ factorial (5 )
18
+
19
+ # Con recursividad
20
+ def factorial_2 (number : int ) -> int : # Li dic que m'ha de retornar un enter
21
+ if number < 0 :
22
+ print ("Els números negatius" )
23
+ return 0
24
+ elif number == 0 :
25
+ return 1
26
+
27
+ return number * factorial_2 (number - 1 )
28
+
29
+
30
+ # print(factorial_2(5))
31
+
32
+ numeros = [0 ,1 ]
33
+
34
+ def fibonnacci (posicio : int )-> int :
35
+ num1 = numeros [(len (numeros )- 1 )]
36
+ num2 = numeros [(len (numeros )- 2 )]
37
+ sum_fibo = num1 + num2
38
+ numeros .append (sum_fibo )
39
+ if (len (numeros ) <= posicio ):
40
+ fibonnacci (posicio )
41
+ else :
42
+ return print (numeros [posicio ])
43
+ fibonnacci (13 )
You can’t perform that action at this time.
0 commit comments