why this unboundlocalerror is getting in python
Difference between en1 and en2, changed 53 character(s)
1)python program to calculate list of prime numbers↵
import math↵
def isPrime(n):↵
    for i in range(2,int(math.sqrt(n))+1):↵
        if(n%i==0):↵
            break↵
    if(i==int(math.sqrt(n))):↵
        return True↵
    else:↵
        print(i)↵
        return False    ↵
n1,n2=map(int,input().split())↵
list1=[]↵
for j in range(n1,n2+1):↵
    if(isPrime(j)):↵
        list1.append(j)↵
print(list1)↵
_________________________________↵
i/p: 3 45↵
Traceback (most recent call last):↵
  File "C:\Users\GRIET\AppData\Local\Programs\Python\Python37-32\isPrime.py", line 14, in <module>↵
    if(isPrime(j)):↵
  File "C:\Users\GRIET\AppData\Local\Programs\Python\Python37-32\isPrime.py", line 6, in isPrime↵
    if(i==int(math.sqrt(n))):↵
UnboundLocalError: local variable 'i' referenced before assignment

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English harishsanaka 2020-08-03 15:54:27 53 Tiny change: '1)python program to calculate list of prime numbers\nimport mat' -> 'import mat'
en1 English harishsanaka 2020-08-03 15:53:41 847 Initial revision (published)