How to get rid of NZEC error in Python?


#1

for item in range(int(input())):
a,b=map(int,input().split())
s=’^’.join([str(i) for i in list(range(a,b+1))])
if eval(s)%2==0:
print(‘Even’)
else:
print(‘Odd’)
Whats wrong in this code? showing the runtime error


#2

One possible reason is the difference between a and b is too much and you are not able to allocate this much of memory. You can’t have a string of size more than 10^8. But if a =1 and b = 10^9 then it’s surely going to give such error. Check the constraint on a, b. Good approach can be this.