python - python中的MemoryError-是否有可能进行修改以解决?

标签 python error-handling

我试图在崇高的文本中运行以下代码:

def max_prime_factor(num):
    divisibles=[]
    prime_facors=[]
    for i in range(1,num):
        if num%i==0:
            divisibles.append(i)
        else:
            continue
    for j in divisibles:
        for k in range(2,j):
            if j%k==0:
                break
            else:
                continue

        prime_facors.append(j)
    return(max(prime_facors))

print(max_prime_factor(600851475143))

使用配备有:

enter image description here

并在sublime文本中得到以下错误。我是否需要修改代码,因为它势不可挡?提前Tnx!

enter image description here

最佳答案

从注释中听起来好像您正在使用Python2。在这种情况下,您将需要使用xrange或range。 xrange与range相同,但是内存效率更高。参见What is the difference between range and xrange functions in Python 2.X?

关于python - python中的MemoryError-是否有可能进行修改以解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62074868/

相关文章:

python ftplib 和 TLS,数据连接问题

c# - 为什么C#声明常量时不能使用匿名类型?

python - 将一列拆分为三个不同的列

python - 如何使用 boto 在 Windows ec2 实例上安装临时存储?

python - 矩阵程序,使用python中的绑定(bind)来停止/启动

python - 我应该如何将 float32 图像转换为 uint8 图像?

vba - VBA 中的错误处理 - 错误继续下一步

tsql - TRY..CATCH Error_Line()…行

.net - NTStatus STATUS_SUCCESS 还是 STATUS_WAIT_0?

jquery - 失败的ajax请求返回的数据在哪里?