# Reduce to One Problem Code: REDONE

Why i am getting wrong answer for this code
try:
def change(arrr):
for i in range(len(arrr)-1):
val = ((arrr[0]*arrr[1])%(109+7) + arrr[0] + arrr[1])%(109+7)
arrr.append(val)
del arrr[0:2]
print(val)

``````time = int(input())
while time>0:
arr = []
size = int(input())
for j in range(size):
val = j+1
arr.append(val)
change(arr)
time-=1
``````

except:
pass
In my local editor it is giving proper solution.

Please format your code using the â€ś</>â€ť â€śPreformatted textâ€ť - this is unrunnable

``````try:
def change(arrr):
for i in range(len(arrr)-1):
val = ((arrr[0]*arrr[1])%(10**9+7) + arrr[0] + arrr[1])%(10**9+7)
arrr.append(val)
del arrr[0:2]
print(val)

time = int(input())
while time>0:
arr = []
size = int(input())
for j in range(size):
val = j+1
arr.append(val)
change(arr)
time-=1
except:
pass`Preformatted text```````

Close enough (except for the literal `Preformatted text` that you appended on the end XD)

Your code throws an exception when run with the example testcase

``````3
1
2
4
``````

but you catch and hide the exception.

Try e.g.

``````try:
def change(arrr):
for i in range(len(arrr)-1):
val = ((arrr[0]*arrr[1])%(10**9+7) + arrr[0] + arrr[1])%(10**9+7)
arrr.append(val)
del arrr[0:2]
print(val)

time = int(input())
while time>0:
arr = []
size = int(input())
for j in range(size):
val = j+1
arr.append(val)
change(arr)
time-=1
except Exception as exc:
print exc

pass
``````

to help you debug. Or just remove the try â€¦ except around the code.

thank you for helping me, but when i remove try except it gives Runtime error (NZEC).

Have you run it on your local machine with the given testcase? That should be your first step

Thank you for pointing mistakes .

1 Like