Recursion: Fibonacci Numbers

  • + 0 comments
    ans = {0,1}
    def fibonacci(n):
        if n <= 1:
            return 1
        c =fibonacci(n-1) + fibonacci(n-2)
        ans.add(c)
        return c
    
    n = int(input())
    fibonacci(n)
    ans = sorted([i for i in ans])
    print(ans[n-1])