Runtime Error Python Code

Help on following code…(python 2.7.2)
Shows runtime error on submission, dunno why.
The question is http://www.codechef.com/problems/PRIME1

def ifprime(n):
    for i in range(2,int(n**0.5)+1,2):
        if n%i == 0:
            return False
        return True
def founc(a,b):
    if a==2:
        print 2
    if a%2 == 0:
        skip = 1
    else:
        skip = 0
    for num in range(a+skip,b+1,2):
        if ifprime(num):
            print num
test_cases = int(raw_input())
for test in range(test_cases):
    a = int(raw_input())
    b = int(raw_input())
    founc(a,b)
    print ""

Hello,

It is a bit of a puzzle to read your program, because the indentation in the post is not correct…

I am not very familiar with raw_input, but according to the help it reads a line of input. The problem statement indicates that a and b are on the same line. You will need to call raw_input() once and process the result (split…) to obtain a and b, instead of calling raw_input() twice to obtain a and b.

There is also a small error in the logic of ifprime. You will probably find it if you look closely. To test: ifprime(9) returns True…

Good luck.

2 Likes