primeNum = [] # list for storing prime numbers having 3 digits and starting with 5 for i in range(500,600): for j in range(2,i): # inner loop goes from 2 to i flag = False # flag initialized False for every iteration if i%j == 0: flag = True # if remaining from i divided by any j equals to zero set flag to True break # break the loop if flag==0: # if flag equals to False i is prime number primeNum.append(i)