uaveiro-leci/1ano/1semestre/fp/aula04/fibonacci.py

11 lines
267 B
Python
Raw Normal View History

2022-10-14 22:03:25 +00:00
def fibonacci(n):
if n == 0: return 0
if n == 1: return 1
return fibonacci(n-1) + fibonacci(n-2)
2022-10-14 22:03:25 +00:00
def main():
n = int(input('Introduza um número: '))
2022-10-18 17:18:56 +00:00
print(f'O {n}º número de Fibonacci é: {fibonacci(n)}')
2022-10-14 22:03:25 +00:00
2022-10-18 17:18:56 +00:00
if __name__ == "__main__":
main()