我想找出 13195 的质因数。
for num in range(1,13196):
x = 13195/num
我希望 x 只存储整数。我已经尝试过 is.integer,但不断出现语法错误。
最佳答案
您可以使用 modulo operator检查一个数字是否被均匀分割,然后只设置 x 等于它。例如:
for num in range(1,13196):
if 13195 % num == 0:
x = int(13195/num)
print(x)
给出:
13195
2639
1885
1015
455
377
203
145
91
65
35
29
13
7
5
1
关于Python:只返回整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43455990/