向量减法python 3,不使用内置函数sum,min,max和zip

时间:2018-06-22 05:28:18

标签: python python-3.x vector

我对使用python 3语言进行编码非常陌生。我正在编写代码,首先将检查两个向量的尺寸,然后如果尺寸匹配,它将计算两个向量的减法。我不确定我的代码哪里出了问题,任何帮助都会很棒。预先谢谢你。

def vecSubtract(vector01,vector02):
    if len(vector01) != len(vector02):
        raise ValueError
    result = []
    total = 0
    for i in range(len(vector01)):
        total += vector01[i] - vector02[i]
        result.append(total)
    return result
vector01 = [2, 3, 4]
vector02 = [4, 2, 1]
print(vecSubtract(vector01,vector02))

2 个答案:

答案 0 :(得分:1)

String toString() {
    return subjectId + " " + height + " " + width + " " + bmianalyzier + " " + categories;
}

答案 1 :(得分:0)

在没有实际运行的情况下,它看起来像这样 总计+ = vector01 [i]-vector02 [i] 是你的问题。只需将“ + =”替换为“ =”。 最好不要将结果总计称为,因为它只是序列中的一个术语。

这个问题很好,因为它需要无需学习特有的python函数就可以理解的代码。