Problem with Python function

if name == “main”:
t=int(input())
while(t>0):
m,n=map(int,input().split())
for num in range(m,n+1):
if is_prime(num):
print(num)
t-=1
print()

def is_prime(num):
if num==2 or num==3:
return True
if num%2==0:
return False
for i in range(3,num,2):
if num%i==0:
return False
return True

I’ m getting error that “is_prime” is not define but just putting def function above all , code working correctly.Can anyone explain me why ?

Python is a interpreted Language. So, all the functions must be declared before they are called. This is the reason why functions are declared before they are called.

2 Likes