你好我是python的新手,并决定练习写一些算法。 我想解决的问题可以在这里找到,如果感兴趣>http://codeforces.com/problemset/problem/791/A为什么在尝试在while循环中覆盖变量时会出现内存错误? (Python)
这是我写的代码来解决这个问题。
a = input("Enter Limak's weight:")
b = input("Enter Bob's Weight:")
i = 0
while (a < b):
a = (a * 3)
b = (b * 2)
i= (i + 1)
print(i)
当我尝试运行我收到以下错误 -
Enter Limak's weight:4
Enter Bob's Weight:7
Traceback (most recent call last):
File "s.py", line 6, in <module>
a = (a * 3)
MemoryError
任何想法的代码?
Python 2或Python 3?这听起来像你在Python 3上,而你正在乘以字符串而不是整数或浮点数。 – user2357112