Help me solving the runtime error(nzec)

    # cook your dish here
t = int(input(""))
print(t)
i= 0
while i <= t:
    i += 1
    if i > t:
        break
    d = int(input(""))
    x = int(input(""))
    y = int(input(""))
    z= int(input(""))
    a = 7*x
    if y > x:
        if d < 7:
            b = d * y
            if z < x:
                c = z * (7-d)
                sum = b + c
    
    print(max(a,sum))

https://discuss.codechef.com/t/tutorial-how-to-debug-an-nzec-error/11221

Are you trying to “Run” without Providing “Custom Input"?

with the custom input

I have tried using
try:
#working code
except Exception:
pass

when I run it, there is no error displayed it displays all the expected output from custom input but when I Submit the answer it shows wrong answer.

The scope of your sum variable is limited to if block. initialize sum to some value after taking input.
btw it’s a good practice not to name your variables which have same name as built-in functions.

1 Like

could you please specify it in the code which i have shared if possible. The mistakes and updates.

my code:

# cook your dish here
try:
    # TODO: write code...
    T = int(input())
    print(T)
    i= 0
    while i <= T:
        i += 1
        if i > T:
            break
        d, x, y, z  = map(int, input().split())
        a = 7*x
        if y > x:
            if d < 7:
                b = d * y
                if z < x:
                    c = z * (7-d)
                    sum = b + c
        
        print(max(a,sum))
    
except Exception:
    pass