Whats the error

ef genp(cb,ob,n,s=[]):
if cb==n:
print (’’.join(s))
return
else:
if ob>cb:
s.append(’)’)
genp(ob,cb+1,n,s)
s.pop()
if ob<cb:
s.append(’(’)
genp(ob+1,cb,n,s)
s.pop()
return

print(genp(0,0,3))

It’s great you got the logic for the problem, and you nearly succeeded in coding it.
These are few silly mistakes you did:

  1. You have changed the order of arguments while calling it, like in declaration your first variable is cb, but while calling recursively your first argument is ob. So just make the function declaration as:
    “def genp(ob,cb,n,s=[]):”
  2. genp function didn’t return anything so just call the function and remove print in the last line.

Hope this cleared your doubt :blush: Keep coding keep growing.

def genp(ob,cb,n,s=[]):
if cb==n:
print (’’.join(s))
return
else:
if ob>cb:
s.append(’)’)
genp(ob,cb+1,n,s)
s.pop()
if ob<cb:
s.append(’(’)
genp(ob+1,cb,n,s)
s.pop()
return

genp(0,0,3)

Are you still facing any problem or not. If not please close the doubt and keep coding.
Or if your doubt is not cleared yet, than plz respond, we would love to clear that.