-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgoritmos.py
More file actions
39 lines (30 loc) · 776 Bytes
/
algoritmos.py
File metadata and controls
39 lines (30 loc) · 776 Bytes
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
"""
>>> recursivo = Recursivo()
>>> recursivo.factorial(5)
120
"""
def fibonacci(number):
if number == 0: return 0
elif number == 1: return 1
else: return fibonacci(number -1) + fibonacci(number - 2)
def palindromo(sentence):
"""Retorna verdadero si el parametro es un palindromo
en caso contrario retorna falso
sentence --String o entero
>>> palindromo("anita lava la tina")
True
>>> palindromo(12321)
True
>>> palindromo("CodigoFacilito")
False
"""
sentence = str(sentence).lower().replace(" ", "")
return sentence == sentence[::-1]
class Recursivo:
def factorial(self, number):
if number == 0; return 1
else: return number * self.factorial(number - 1)
if __name__ == '__main__':
import doctest
doctest.testmod()
doctest.testfile("test.txt")