查看下面的代码,当我输入一个负数时,似乎没有错误,但是平方根不可能是负数,所以我不知道为什么会这样。
import math
d=[]
while True:
z=int(raw_input())
if (z>0 and math.sqrt(z)): d.append(int(z))
空闲时:
math.sqrt(int(-1))
Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
math.sqrt(int(-1))
ValueError: math domain error