Question-
Generate all prime numbers between two given numbers.
https://www.spoj.com/problems/PRIME1/
My attempt-
I used segmented sieve method.
t=int(input())
import math
def segsieve(x):
    if x==1:
        return False
    for i in range(2,int(math.sqrt(x))+1):
        if x%i==0:
            return False
    return True
while t>0:
    f,l=map(int,input().split())
    for j in range(f,l):
        a=segsieve(j)
        if a==True:
            print(j)
    t-=1
Issue-
I am getting time limit exceeded. How can I make it faster?

t, so your code runs an infinite loop, exceeding any time limit. \$\endgroup\$t(causing an infinite loop) was not addressed in the answer at all. \$\endgroup\$