I have an array that I would like to perform 2 calculations on.
1) I want to take the largest integer not greater than x for every array value, divide that value by 3, then subtract 2.
2) I then want to sum the array values.
Here is my script:
mass = [1,2,3,4,5]
def Multiply(x):
return (math.floor(x/3) - 2)
for i in mass:
new_mass = Multiply(i)
print(new_mass)
When I run the script it works as expected. I get:
-2 -2 -1 -1 -1
However, when try to sum the new_mass in a "total" variable I get the following error:
total = sum(new_mass)
print(total)
"TypeError: 'int' object is not iterable"
Can someone please help? Below is the complete code:
mass = [1,2,3,4,5]
def Multiply(x):
return (math.floor(x/3) - 2)
for i in mass:
new_mass = Multiply(i)
print(new_mass)
total = sum(new_mass)
print(total)