defprime():n=raw_input('whichprimenumber?')a=2cnt=0isPrime=FalsewhilenotisPrime:ifa<=2:cnt+=1##print'the',cnt,'thprimenumberis',aa+=1else:whilenotisPrime:forbinrange(2,a)...
def prime():
n = raw_input('which prime number?')
a = 2
cnt = 0
isPrime = False
while not isPrime:
if a <= 2:
cnt += 1
## print 'the ',cnt,'th prime number is',a
a += 1
else:
while not isPrime:
for b in range(2,a):
if a % b != 0:
isPrime = True
else:
isPrime = False
a += 1
break
if isPrime:
cnt += 1
## print 'the ',cnt,'th prime number is',a
isPrime = False
if cnt == n:
isPrime = True
print 'the',n,'th prime number is',a
break
a += 1
------------------------------------------------
自己写的计算第n个质数的程序,为什么这样写代码程序终止不了?要怎么改正??谢谢
展开