超级新编程。试图在数组中总结负数。这是我到目前为止所得到的。
def ma # define the variables needed to test the required functions
myvals = [1, -1, 2, -3.5, 8.5]
ArraySumNegative(myvals):
if i<0
printsum(myvals)
答案 0 :(得分:0)
我相信你正在寻找这样的功能:
def sumOfNegativ(arrayOfValue):
res = 0
for i in arrayOfValue:
if i < 0:
res += i
return res
并显示结果:
print(sumOfNegativ(myvals))