You are breaking out of one for loop but you are still in the other for loop. The while loop doesn't automatically end as soon as p > 10. It checks this condition once every time through the whole while loop.

p = 0while p < 10: for n in range(2, 50): #Everytime you get to the break you end up back here #until this loop finishes. for r in range(2, n): p += 1 break

print(p)

The above, as you can see, won't end when p exceeds 10.

There is no multi loop break in python. You can accomplish similar things by using flags but at this point I would actually suggest you completely re-examine your approach. Another interesting thing to note is you will only need to check for divisors up to the square root of your number. If you think about it you will realize why.