Python TypeError:并非所有参数都在字符串格式化期间转换 [英] Python TypeError: not all arguments converted during string formatting
本文介绍了Python TypeError:并非所有参数都在字符串格式化期间转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我绝对是python的初学者.我编写了一个程序来检查一个数是否为素数.但它给了我上述类型错误
该错误的含义是什么,我该如何解决?
我看到了相同标题的问题.但我不明白如何解决它.所以我问这个问题.
num = ( "哪个不.你想检查素数:" )我 = 1k = 0while(i <= num):if(num % i == 0): #idle 在这里显示类型错误k=k+1我=我+1如果(k == 2):打印 "%d 是质数" % num别的:打印 "%d 不是质数" % num
解决方案
num
is string.
我想你错过了raw_input()
:
I am an absolute beginner of python. I had coded a program for checking whether a number is prime or not. but it is giving me the above type error
What is the meaning of that error and how should I resolve it?
I saw the questions with same title. but I didn't understand how to resolve it. so I am asking this question.
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
is string.
>>> 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
>>>
I think you missed 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
这篇关于Python TypeError:并非所有参数都在字符串格式化期间转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文