In: Computer Science
Using Python 3, define mySum function that supposed to return the sum of a list of numbers (and 0 if that list is empty), but it has one or more errors in it. Write test cases to determine what errors there are.
CODE:
def mySum(arr):
if(len(arr)==0):
return 0
else:
return sum(arr)
arr=[1,2,5,4]
print("Sum of list numbers is",mySum(arr))
assert mySum([])==0
print("test pass")
assert mySum([1,2])==0
print("test failed")
OUTPUT:
If you have any doubts please COMMENT...
If you understand the answer please give THUMBS UP...