def multAll(A, k):
# takes an array of integers and an int, and multiplies each integer by the int.
for i in A:
i = i*k
return i
# test 1
A = [5,12,31,7,25]
multAll(A, 10)
print(A) # should print [50,120,310,70,250]
我在 multAll 中做错了什么,没有给我正确的答案?
When return i
第一次在你的函数中发生,函数停止并返回当前的i
.
def multAll(A, k):
return_value = []
for i in A:
i = i*k
return_value.append(i)
return return_value
像这样,一个完整的列表return_value
创建并返回该列表。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)