我已编写此代码来计算二次公式:
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.
任何人都可以告诉我为什么会这样,如果可能的话,还有办法解决这个问题吗?感谢。
答案 0 :(得分:0)
要做一个sqrt,你可以这样做:
def sqrt(num):
return num ** 0.5
我会尝试为您提供与您的问题相关的更多信息,但现在尝试用您的sqrt替换您的sqrt。