harishsanaka's blog

By harishsanaka, history, 2 months ago, In English

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 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

 
 
 
 
  • Vote: I like it
  • -8
  • Vote: I do not like it

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by harishsanaka (previous revision, new revision, compare).

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

to find prime numbers between two numbers