My Objective: To find and print the sum of all the items in the list via function
My Code:
def list_sum(x):
if type(x)!='list':
print("Invalid List item!")
if type(x)=='list':
list_length = len(x)
total = 0
i = 0
for i in range (list_length):
total +=x[i]
i+=1
print("The sum of all items in the list is: ",total)
samples = [1,3,5,6,8,45,67,89]
list_sum(samples)
My Output:
<class 'list'>
Invalid List item!
Expected: 224
Why am I getting the output I am getting?