1

I have written this code to calculate the quadratic formula:

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

Never minding the rather crappy style, when the input is not a number, I get this error:

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.

Can anyone tell me why this is happening and, if possible, a way to fix it? Thanks.

Expain
  • 19
  • 5

1 Answers1

0

To do a sqrt, you can simply do this:

def sqrt(num):
    return num ** 0.5

I'll try to give you more info related to your problem, but for now try to replace your sqrt with that one.

AbyxDev
  • 1,363
  • 16
  • 30