擅长:python、mysql、java
<p>代码中还有更多的问题:<code>while</code>循环只能达到给定数字的平方根,但打印<code>prime num</code>表示k==2。在这个代码中只有一个除数,它是1。你知道吗</p>
<p>更重要的是,你可以从<code>i=2</code>开始,所以一个素数有0个除数。在那之后,最后一个问题是1不是素数。所以代码是这样的:</p>
<pre><code>import math
a = int(raw_input("Enter a number:"))
k = 0
i = 2
s = math.sqrt(a)
#print(s)
while i <= s:
if a % i == 0:
k += 1
i += 1
#print(k)
if k == 0 and a > 1:
print "prime num"
else:
print "normal num"
</code></pre>