Professional Documents
Culture Documents
Take an input from user in string format “12,3,6,9,7,56,7,96,4” and pass that value to a recursive
function which will keep adding the values of that string
“12,3,6,9,7,56,7,96,4”
“15,6,9,7,56,7,96,4”
“21,9,7,56,7,96,4”
“30,7,56,7,96,4”
“37,56,7,96,4”
Conditions:
CODE:
def addition(mystring):
if mystring!= ' ':
result = mystring.split(',', maxsplit = 2)
if len(result) > 1:
answer = int(result[0]) + int(result[1])
if len(result) > 2:
mystring = str(answer)+ ',' +result[2]
addition(mystring)
else:
print(answer)
addition("12,3,6,9,7,56,7,96,4")