如何避免在 python 中出现内存错误?
How do I avoid getting a memory error in python?
Traceback (most recent call last):
File "C:\Users\user\Desktop\modular inverse.py", line 12, in <module>
Multiples_of_e.append(e*f)
MemoryError
这是代码:
Multiples_of_e = []
e=input("Enter the exponent: ")
f=1
for i in range(100000):
Multiples_of_e.append(e*f)
f+=1
如果我删除这两行
e=input("Enter the exponent: ")
totent=input("Enter the totent: ")
我只是用代码中的值替换了每个变量,问题就解决了,有没有办法在不这样做的情况下完成这项工作?
您忘记将输入转换为整数。你的循环乘以字符串。
Traceback (most recent call last):
File "C:\Users\user\Desktop\modular inverse.py", line 12, in <module>
Multiples_of_e.append(e*f)
MemoryError
这是代码:
Multiples_of_e = []
e=input("Enter the exponent: ")
f=1
for i in range(100000):
Multiples_of_e.append(e*f)
f+=1
如果我删除这两行
e=input("Enter the exponent: ")
totent=input("Enter the totent: ")
我只是用代码中的值替换了每个变量,问题就解决了,有没有办法在不这样做的情况下完成这项工作?
您忘记将输入转换为整数。你的循环乘以字符串。