我正在尝试编写一个脚本,它将返回所有的素数,直到您输入的数字为止,问题是如果您问python它是17/2
多少,它会回答8,也会回答27/2
,它会回答13,我如何修复它?你知道吗
我试过float()
但没用。你知道吗
编辑:我写的剧本,直到现在:
array=[2,3,5,7]
num=int(raw_input("Please enter a number higher then 8: ex:12\n"))
for i in range(8,num):
b=float(i)
if b%2.0 and b%3.0 and b%4.0 and b%5.0 and b%6.0 and b%7.0 and b&8.0 and b%9.0!=0:
array.append(b)
print array
如果要使用整数,可以使用:
输出:
我想你想要这个
对于num=25,它输出:(python 2.7.6)
对于num=100,它输出:
试试这个
相关问题 更多 >
编程相关推荐