我试图用二次公式将标准形式的二次方程转换成因式,但在我开始做数学的那一部分,我得到了一个错误。它似乎与我使用的浮标有问题,但我不知道为什么,我也不知道如何修复它。
这是我得到的错误:
Traceback (most recent call last):
File "C:\Users\Josef\Documents\Python\standardFactored.py", line 25, in <module>
rightS = b^2-4*a*c
TypeError: unsupported operand type(s) for ^: 'float' and 'float'下面是代码:
print("This program will convert standard form quadratic equations to "
"factored form. ax^2+bx+c --> a(x+ )(x+ )")
while True:
try:
a = float(raw_input("a = "))
break
except:
print("that is not a valid number")
while True:
try:
b = float(raw_input("b = "))
break
except:
print("that is not a valid number")
while True:
try:
c = float(raw_input("c = "))
break
except:
print("that is not a valid number")
rightS = b^2-4*a*c
try:
math.sqrt(rightS)
except:
("There is no factored for for this equation")
quit()发布于 2016-09-12 01:29:34
^操作符可能不像您所期望的那样。它是二进制异或,或eX包含或运算符。XOR运算符不使用浮点数,从而产生错误。这个错误基本上表示它不能在两个浮动上执行操作。对于指数,使用双星号。请参阅Python 这里。
例如,a到电源b是:
a ** b就你而言,这将是:
rightS = b ** 2 - 4 * a * chttps://stackoverflow.com/questions/39442260
复制相似问题