1 / 4
May 2016

So basically I tried my code, it is working but I get an error runtime error (NZEC).

Here is my code:

def is_prime(x):
	if x > 1:
		n = x // 2
		for i in range(2, n + 1):
			if x % i == 0:
				return False
		return True
	else:
		return False

def solution():
	x = int(input())
	y = int(input())
	for n in range(x, y+1):
		if is_prime(n):
			print(n)

solution()
  • created

    May '16
  • last reply

    May '21
  • 3

    replies

  • 1.3k

    views

  • 4

    users

You have to consider the way spoj 'feeds' the input to your code and how python processes it. The input() command always reads an entire line and returns a string. So you will often have to split the string before converting into integer. .split() is your friend. It is always a good idea to test your code at ideone.com before submitting it to spoj - it will help to find this kind of errors (and more). After resolving the input issue you will have to find a faster algorithm. :wink:

26 days later

to receive the multiple inputs in one line you need to write
x,y=map(int, raw_input().split())
it is for two variables but you can also use it with a list instead of x and y.

4 years later

I am trying to understand why I keep on getting the error “Standard input is empty” in the code below when clearly I am asking for input. This it the code for the prime generator puzzle but the detail of the calculation is not relevant.

k=int(input()) #number of test cases
for i in range(1,k+1):
m,n=map(int, input().split())
primes=prime_sieve_range(m,n)
for p in primes:
print§
print(’’)

Kind regard
H