pythonfor-loopsumrangeinner-product

Python The inner product is <function innerproduct at 0x000001EF5A6A7D30> error


My code is below, but I'm getting this weird output for my inner product code and don't know why it's not calculating the correct inner product. nums and nums2 ask the user for an equal list of numbers in which the inner product will be calculated. Any assistance would be appreciated.

def innerproduct(nums, nums2):
    sum = 0.0
    for i in range(len(nums)):
        sum += nums[i] * nums2[i]
    return innerproduct

Solution

  • The error arising because of the return innerproduct statement since that is the name of the function.

    Instead, did you mean to return the sum?

    def innerproduct(nums, nums2):
        sum = 0.0
        for i in range(len(nums)):
            sum += nums[i] * nums2[i]
        return sum