Sort by

recency

|

480 Discussions

|

  • + 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!

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