我绝对是python的初学者。我已经编写了一个程序来检查数字是否为质数。但这给了我上面的类型错误
该错误的含义是什么,我该如何解决?
我看到了标题相同的问题。但我不知道如何解决。所以我问这个问题。
num = ( "which no. u want to check prime or not:" )
i = 1
k = 0
while(i <= num):
if(num % i == 0): #idle is showing type error here
k=k+1
i=i+1
if(k == 2):
print "%d is prime number" % num
else:
print "%d is not a prime no" % num
num
是字符串。
>>> num = ( "which no. u want to check prime or not:" )
>>> num % 1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting
>>>
我想你错过了raw_input()
:
>>> num = int(raw_input( "which no. u want to check prime or not:" ))
which no. u want to check prime or not:1
>>> num
1
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句