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:
Sol:
#function
def format(q):
if q!='':
num=q.split(',',maxsplit=2)
if len(num)>1:
res=int(num[0])+int(num[1])
if len(num)>2:
q=str(res)+','+num[2]
format(q)
else:
print(res)
else:
format("12,3,6,9,7,56,7,96,4")