Python 2错误:";inspect模块中存在内部Python错误
我编写了以下代码来计算二次公式:Python 2错误:";inspect模块中存在内部Python错误,python,python-2.x,Python,Python 2.x,我编写了以下代码来计算二次公式: from numpy.lib.scimath import sqrt as csqrt a = raw_input("a?") b = raw_input("b?") c = raw_input("c?") def numcheck(x): try: i = float(x) return True except (ValueError, TypeError): return False if
from numpy.lib.scimath import sqrt as csqrt
a = raw_input("a?")
b = raw_input("b?")
c = raw_input("c?")
def numcheck(x):
try:
i = float(x)
return True
except (ValueError, TypeError):
return False
if numcheck(a)==True:
a=int(a)
else:
print "a is not a number"
if numcheck(b)==True:
b=int(b)
else:
print "b is not a number"
if numcheck(c)==True:
c=int(c)
else:
print "b is not a number"
sqrt= ((b*b) - (4* (a*c)))
x_minus= (-b+(csqrt(sqrt)))/(2*a)
x_minus=str(x_minus)
x_plus= (-b-(csqrt(sqrt)))/(2*a)
x_plus=str(x_plus)
print "The solution is "+x_plus+" or "+x_minus
不管是什么蹩脚的风格,当输入不是数字时,我会出现以下错误:
Traceback (most recent call last):
File "build\bdist.win32\egg\IPython\core\ultratb.py", line 776, in structured_traceback
File "build\bdist.win32\egg\IPython\core\ultratb.py", line 230, in wrapped
File "build\bdist.win32\egg\IPython\core\ultratb.py", line 267, in _fixed_getinnerframes
UnicodeDecodeError: 'ascii' codec can't decode byte 0xba in position 51: ordinal not in range(128)
ERROR: Internal Python error in the inspect module.
Below is the traceback from this internal error.
Unfortunately, your original traceback can not be constructed.
有人能告诉我为什么会发生这种情况,如果可能的话,还有一种解决方法吗?谢谢。要进行sqrt,您只需执行以下操作:
def sqrt(num):
return num ** 0.5
我将尝试向您提供与您的问题相关的更多信息,但现在请尝试将您的sqrt替换为该问题。要执行sqrt,您只需执行以下操作:
def sqrt(num):
return num ** 0.5
我将尝试向您提供与您的问题相关的更多信息,但现在请尝试用该问题替换您的sqrt。看起来像是一个IPython错误。您有没有可能改用Python 3?看起来像是一个IPython错误。您有没有可能改用Python 3?