Getting value error

Once my first test case gets executed , i am getting value error for list, how can i solve this problem?
Code link:- https://drive.google.com/file/d/13Hd6neVCXGprRfXBe5D1W8SV4JDeulDV/view?usp=sharing

Hey @saksham_thukral, you can remove that error by replacing the keywords input by input1 and list by list1 everywhere in your code. You cannot use keywords as variable names in python. So your final code should look something like this :

t= int(input()) # number of test cases
while(t>0):
    input1 = list(map(int,input().split()))
    
    
    n = input1[0]
    m = input1[1]
    list1 = []
    for i in range(n,m+1):
        #print(i)
        flag = 0
        if i==1:
            flag=1
        else:
            for j in range(2,i//2+1):
                if(i%j == 0):
                    flag = 1

            if flag == 0:
                list1.append(i)
            else:
                continue

    print(*list1)
    t = t-1

I hope this helps you resolve this error :+1:
Happy Learning :slight_smile:

Now i am getting time limit exceed error ie TLE, how can resolve this error in my code?

You need to optimise your code so that it takes less iterations to produce the output ! Try to reduce the number of for loops and iterations your code is taking !

I hope this helps !
Happy coding :slight_smile:

how can i reduce the number of iterations , as for now, if i take example of 1-10, and if my i reaches at β€˜4’, then it checks the its factors upto β€˜2’, how can i even further reduce the number of iterations, as in that case on checking for even β€˜4’ it will put it into prime numbers as the loop will be running only upto β€˜1’ for β€˜4’

There’s a technique called Sieve of Eratosthenes. Read about that and you would get your answer :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.