我是编程新手,开始学习python。如果数字a= 1,2,3,4,5逻辑应该是1-2-3-4-5,则得到的结果为-13。有人帮我解决这个问题的python代码。
发布于 2022-02-10 18:04:26
最简单的解决方案是使用一个for循环和一个临时变量,每次减去这个数字。
a = [1,2,3,4,5] #initiate array
temp = a[0] #set the value to the first number
for i in a[1:]:
temp -= i #update valuehttps://stackoverflow.com/questions/71070044
复制相似问题