【发布时间】:2020-11-20 15:39:32
【问题描述】:
我尝试执行两个脚本,一个带有导入的模块,一个没有。
我双击带有模块的那个,一个窗口出现并迅速消失,然后我尝试另一个没有,它起作用了。
有人可以帮我弄清楚吗?谢谢。
精度:我已经尝试了其他模块的其他脚本,但它不起作用,两个脚本都没有任何错误。 我在 Windows 10 上,两个脚本都是打印给定数字的主要因素,一个带有数学模块,另一个没有。 我仍然可以使用我的 IDE 执行带有模块的那个,但我不想打开我的 IDE 来执行带有模块的脚本。
如果你想要脚本:
# The one without the module ik it's not optimized
num = 56475871
nvNum = 2
nbsPmrs = []
res = []
for nvNum in range(num):
if not nvNum % 2 == 0 and not nvNum % 3 == 0 and not nvNum % 5 == 0 and not nvNum == 1 or nvNum == 2 or nvNum == 3 or nvNum == 5:
nbsPmrs.append(nvNum)
for a in range(1, len(nbsPmrs), 1):
if num % nbsPmrs[a] == 0:
res.append(nbsPmrs[a])
print(res)
# -----------------------------------------------------
# The one with the module
from math import *
num = 56475871
res = []
t = int(sqrt(num))
for i in range(t):
while num % 2 == 0:
num //= 2
res.append(2)
if num % 2 != 0:
break
for a in range(3, t, 1):
if num % a == 0:
num //= a
res.append(a)
res.append(num)
print(res)
【问题讨论】:
-
细节太少,无法帮助您。您能否制作一个具有相同行为的非常小的程序,并将其发布在这里。另外,请指定操作系统。
-
@Stefan 我在windows上,基本上它在打印一个数字的质因数,使用的模块是数学来计算一个数字的平方根
-
你能提供代码吗?我认为这是从 IDE 或命令行运行时显示的简单粗壮示例,从 Windows 双击文件时不会发生这种情况
-
@LouieC 我编辑了原文,所以有代码