【发布时间】:2015-09-30 01:29:25
【问题描述】:
我有检查数字是质数还是音符的代码
当我运行它给我一个错误
我的代码:
a = int (input("your numbre :"))
b = range(1,a+1)
if a%b == 0:
for i in b :
if b == a or b == 1:
print("the numbre you input is prim number")
else:
print("the nmubre you input is note prem numbre")
产生的错误:
Traceback (most recent call last):
File "C:\Users\admin\Desktop\chap8ex2.py", line 3, in <module>
if a%b == 0:
TypeError: unsupported operand type(s) for %: 'int' and 'range'
【问题讨论】:
-
错误告诉你到底出了什么问题,你不能按范围进行 mod 和 int
-
我无法修复它你能帮我吗
-
展示我的正确方式
-
另外,如果这恰好是针对某个 Project Euler:请参阅:stackoverflow.com/questions/2068372/…(因为逐个检查素数 = 不是项目 euler 的正确方法)