Python 2 错误:"检查模块中的内部 Python 错误



我写了这段代码来计算二次公式:

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 "buildbdist.win32eggIPythoncoreultratb.py", line 776, in structured_traceback
File "buildbdist.win32eggIPythoncoreultratb.py", line 230, in wrapped
File "buildbdist.win32eggIPythoncoreultratb.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。

最新更新