Oct-19-2019, 07:36 AM
I am trying to figure out what's wrong with the code. It's supposed to be a function that counts how many times the sum of some string's elements are equal to an input number. No other libraries are supposed to be used.
For example:
string='1,2,3'
number=3
For example:
string='1,2,3'
number=3
Output:2 def calculate(string, number):
string=''
result=0
new_list=[]
new_list=[int(x) for x in string.split(',')]
for i in range(0, len(new_list)+1,-1):
sum(new_list)
if sum(new_list)==number:
result+= 1
else:
continue
i+=1
return resultError:ValueError: invalid literal for int() with base 10: ''
