You are on page 1of 1

Task 1:

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:

1. No loops in the function


2. You can’t slice more then 2 values at the time
3. You can’t convert that string into a composite data type(list,dict,tuple,set)

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:

print("ENTER THE STRING")

format("12,3,6,9,7,56,7,96,4")

You might also like