Skip to content

Commit

Permalink
2.3 - Implementação e asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
vbuxbaum committed Apr 3, 2021
1 parent fe2fa17 commit 479791d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions 2_paradigmas/3_fibonacci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Fibonacci:
@classmethod
def recursivo(cls, n):
if n < 2:
return n
else:
return cls.recursivo(n - 1) + cls.recursivo(n - 2)

@classmethod
def iterativo(cls, n):
primeiro = 0
segundo = 1
for _ in range(n):
primeiro = segundo + primeiro
segundo = primeiro - segundo
return primeiro


if __name__ == "__main__":
teste_recursivo = Fibonacci.recursivo(7)
teste_iterativo = Fibonacci.iterativo(7)

assert teste_recursivo == 13
assert teste_iterativo == 13

0 comments on commit 479791d

Please sign in to comment.