def prime(m,n):
ps = [1,2]
for i in range(3,m):
fork in range(2,i//2+1):
if i%k == 0:
breakelse:
ps.append(i)
if n > len(ps):
raise IndexError("超出范围")
else:
print(ps,ps[-n])
prime(100,10)
达拉崩吧叭叭叭的博客I'm new to Python and I thought I'd try to learn the ropes a bit by writing a function to find the nth prime number, however I can't get my code to work properly. No doubt this is due to me missing so...
weixin_39931923的博客本文实例讲述了Python编程判断一个正整数是否为素数的方法。,具体如下:import stringimport math#判断是否素数的函数def isPrime(n):if(n2):for d in range(2,int(math.ceil(math.sqrt(n))+1)):if(n%d==0):return ...