I get NZE error while submitting the following python code while solving practise problems of ccdsap foundation..I am a beginner and would really be grateful of someone can help me out!

I get the NZEC RE error that is shown in the uploaded pic when i submit the code. Please help me out!

The problem link:
https://www.codechef.com/problems/CNOTE

Mycode:
t=int(input())
while(t>0):
x,y,k,n=map(int,input().strip().split())
page=x-y
for j in range(n):
p,c=map(int,input().strip().split())
lc=0
if((c<=k) and (p>=page)):
lc=lc+1
break
else:
continue
if(lc>0):
print(“Luckychef”)
else:
print(“Unluckychef”)
t=t-1

2 Likes

You must complete the input.
But in your code, you break your loop before reading all (n) input.
That’s why your program start reading from where you left. it deserve 4 values (x, y, k, n) but it found 2 values (P, C). Input mismatching provide NZEC error.

Solution:

import sys

def main():
  t = int(sys.stdin.readline())
  
  for _ in range(t):
    x, y, k, n = map(int, sys.stdin.readline().split())
    pg = x - y
    flag = False
    for _ in range(n):
      p, c = map(int, sys.stdin.readline().split())
      
      if p >= pg and c <= k:
        flag = True
    
    print("LuckyChef") if (flag is True) else print("UnluckyChef")

if __name__ == "__main__":
  main()

Note: Use sys module for std input. It will make your program faster.

:white_check_mark: fast => sys.stdin.readline().split()
:x: slow => input().split()

2 Likes