2016-06-08 39 views
0

我使用Python版本3.5和输入此代码为素数:::不受支持的opperand类型错误。我使用<code>input()</code>它在使用Python版本3

  num=input("enter number to be checked : ") 
     ctr=0 
     i=1 
     for i in range(1,(num/2)+1): 
       if(num%i==0): 
       ctr+=1 

     if(ctr==0): 
       print(num," is prime") 
     else: 
       print(num," is not prime") 

和收到此错误::::

  enter number to be checked : 5 
     Traceback (most recent call last) 
      file "prime.py", line 4 in (module) 
       for i in range(1,(num/2)+1): 
     type error: unsupported opperand type(s) for/:str and int 
+0

将您的输入作为'int'读入,如'num = int(input(“enter number of checked:”))''。 – shivsn

回答

0

是一个字符串值,而不是一个int

变化到

num=int(input("enter number to be checked : ")) 

但是,当输入一个非数字值时,这会产生一个ValueError,您可能想要在检查中生成。

相关问题