RosettaCodeData/Task/Loops-Increment-loop-index-within-loop-body/Python/loops-increment-loop-index-within-loop-body-1.py

21 lines
366 B
Python
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
def isPrime(n):
for x in 2, 3:
if not n % x:
return n == x
d = 5
while d * d <= n:
for x in 2, 4:
if not n % d:
return False
d += x
return True
i = 42
n = 0
while n < 42:
if isPrime(i):
n += 1
print('n = {:2} {:20,}'.format(n, i))
i += i - 1
i += 1