import sys
num = int(sys.stdin.readline())
while (num != 42):
sys.stdout.write(num)
num = sys.stdin.readline()
Why does the above code give an NZEC runtime error?
import sys
num = int(sys.stdin.readline())
while (num != 42):
sys.stdout.write(num)
num = sys.stdin.readline()
Why does the above code give an NZEC runtime error?
it’s because the file used to feed the standard input has an end (as every file actually). when you try to read something without considering maybe there’s no data to read anymore, Python raises an exception and you get NZEC by the online judge. it could also come from the fact that, maybe the data you read cannot be converted to an integer, but if i remember well the problem you’re talking about, the input data should be consisting only of integers, so it’s not the glitch here. last thing, why not using raw_input() and print(), instead of sys.stdin.read() and sys.stdout.write() ?
Your suggestion to use raw_input() and print(), instead of sys.stdin.read() and sys.stdout.write() solved my problem.
Thank you!
last line should be num = int(sys.stdin.readline())
n=int(input());
maxdif=-1;
for i in range(n):
a=int(input());
b=int(input());
if abs(a-b)>maxdif:
if a>b:
win=1;
maxdif=a-b;
else:
win=2;
maxdif=b-a;
print win, maxdif
this program is giving me a Nez runtime error can anyone help me out ???..
def f():
x = int(raw_input())
y = float(raw_input())
s = 0
if x % 5 == 0:
if x <= y:
s = y - x - 0.50
print s
else:
print y
else:
print y
f()
def home():
x=[]
for number in range(0,4):
value = int(input('Enter the values for %dth element'%number))
x.append(value)
if x[2] - x[0] > 0 and x[1] - x[3] == 0:
print ('right')
elif x[0] - x[2] > 0 and x[1] - x[3] == 0:
print('left')
elif x[0]-x[2] == 0 and x[1] - x[3] > 0 :
print ('down')
elif x[0] - x[2] == 0 and x[3] - x[1] > 0 :
print ('up')
else :
print (‘sad’)
test_case= int(input(‘Enter the number of test cases’))
for no in range(0,test_case):
home()
I’m getting NZEC Error for this code. Someone please help! Thanks in advance
w = input()
print(w)
I am getting an nzec error for this code on the chef compiler, not IDLE
@srirammurali91 Make sure you are using Python 3.5 on codechef,using Python 2 will give NZEC as syntax for Python 2 is different.
I am getting NZEC on this, however it works fine in IDLE:
z=0
e=0
l=0
r=0
lis=[]
poss=[]
data=[]
times=input()
def getDay(n):
if(n=="sunday"):
s=0
elif(n=="monday"):
s=1
elif(n=="tuesday"):
s=2
elif(n=="wednesday"):
s=3
elif(n=="thursday"):
s=4
elif(n=="friday"):
s=5
elif(n=="saturday"):
s=6
return s
for i in range(0,int(times)):
data=input().split()
z=(getDay(data[0]))
e=(getDay(data[1]))
l=(int(data[2]))
r=(int(data[3]))
for j in range(1,15):
lis.append((7*j+e)-z+1)
for j in lis:
if(j>=l and j<=r):
poss.append(j)
if(len(poss)==0):
print("impossible")
elif(len(poss)==1):
print(poss[i])
else:
print("many")
list=[]
poss=[]
in your second option for print, poss[i] should be poss[0], probably.