Sort by

recency

|

481 Discussions

|

  • + 0 comments
    cube = lambda x: pow(x, 3)
    
    def fibonacci(n):
        if n == 0:
            return []
        elif n == 1:
            return [0]
        elif n == 2:
            return [0, 1]
        else:
            fib_seq = [0, 1]
            for i in range(2, n):
                fib_seq.append(fib_seq[-1] + fib_seq[-2])
            return fib_seq
    
    if __name__ == '__main__':
        n = int(input())
        print(list(map(cube, fibonacci(n))))
    
  • + 0 comments

    Here's my code:

    cube = lambda x: x**3
    
    def fibonacci(n):
        res = [0, 1]
        for i in range(2, n):
            res.append(res[i - 1] + res[i - 2])
        return res[:n]
    
  • + 0 comments

    cube = lambda x:x**3

    def fibonacci(n): # return a list of fibonacci numbers f = [0] a, b = 0, 1

    if n == 0:
        return []
    else:
        for i in range(1, n):
            a, b = b, a + b
            f.append(a)
    return f
    

    if name == 'main': n = int(input()) print(list(map(cube, fibonacci(n))))

  • + 0 comments
    cube = lambda x: x**3
    def fibonacci(n):
        f = []
        a, b = 0, 1
        for _ in range(n):
            f.append(a)
            a, b = b, a + b
        return f
    if __name__ == '__main__':
        n = int(input())
        print(list(map(cube, fibonacci(n))))
    
  • + 0 comments
    cube = lambda x: x**3
    
    def fibonacci(n):
        fibonacci_numbers = []
        an = 0
        an_1 = 1
        
        for _ in range(n):
            if len(fibonacci_numbers) == 0:
                fibonacci_numbers.append(an)
            elif len(fibonacci_numbers) == 1:
                fibonacci_numbers.append(an_1)
            else:
                an_2 = an + an_1
                fibonacci_numbers.append(an_2)
                an = an_1
                an_1 = an_2
        
        return fibonacci_numbers[:n]
    
    if __name__ == '__main__':
        n = int(input())
        print(list(map(cube, fibonacci(n))))
    

    I tried to write my code as comprehensible as possible!