【发布时间】:2017-12-16 17:33:01
【问题描述】:
我有一个愚蠢的问题,所以只需要简单的练习就可以得到一些帮助。
我得到:“ValueError:int() 的无效文字,基数为 10:'12.449899598'”
-尝试运行此代码时:
def find_next_square(sq):
# Return the next square if sq is a square, -1 otherwise
from decimal import Decimal
import math
x = math.sqrt(sq)
y = str(x)
z = y.rstrip('0').rstrip('.') if '.' in y else y
for k in z:
if k != '.':
a = int(z)
return (a+1) * (a+1)
else:
return -1
四个样本测试都是阳性的,只是这个错误导致无法通过练习.. 提前感谢您的提示。
【问题讨论】:
标签: python-2.7