def sum_all(*num):
for number in range(num):
sq = pow(number,2)
total = sum(sq)
return total
So trying to write a function that can take arbitrary arguments and return the sum of the squares of the argument…not sure how to cycle through the integer values in a tuple (also if the arguments were floats with decimals how would the code change?)
>Solution :
When passing arguments using * the argument is a tuple, which contains all the values. I’ve changed the name to be pluralized.
def sum_all(*nums):
total = 0
for number in nums:
sq = pow(number,2)
total += sq
return total
or more concisely
def sum_all(*nums):
return sum(number**2 for number in nums)