Time exceeded ! is it because of recursion or because of adding file error handling

def gen(openb,closeb,n,s=[]):
if(closeb==n):
print("".join(s))
return
else:
if(openb>closeb):
s.append(’)’)
gen(openb,closeb+1,n,s)
s.pop()
if(openb<n):
s.append(’(’)
gen(openb+1,closeb,n,s)
return

while True:
try:
value = int(input())
gen(0,0,value) # next line was found
except (EOFError):
break #end of file reached

Hey @personifier997, can you please explain me why did you use try except blocks in this program ?

Thanks ! :slight_smile:

it was generating EOF error so to remove that i used try and except error

Hey @personifier997, for dealing with EOF error, you don’t have to use error handling techniques. EOF error occurs when you don’t provide any custom input and try to compile the code. I request you to remove try & except blocks and compiler the normal code after providing custom input.

I hope this resolves your doubt ! :+1:
Happy Learning ! :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.