# quadratic.py
# A program that computes the real roots fo a quadratic equation.
# Illustrates the use of the math library
# Note: This program crashes if the equation has no real roots
import math # math makes the library available
def main():
print "This program finds the real solutions to a quadratic"
a, b, c = input("Please enter the coefficients (a, b, c): ")
discRoot = math.sqrt(b * b - 4 * a * c)
root1 = (-b +discRoot) / (2 * a)
root2 = (-b +discRoot) / (2 * a)
print "The solutions are: ", root1 , root2
main()
她是我得到的错误:Macintosh-7:python andrewmetersky$ python quadratic.py
The answer to my homework question: what is i+x+j =
Traceback (most recent call last):
File "quadratic.py", line 6, in
import math # math makes the library available
File "/Users/andrewmetersky/Desktop/Programming/Python/math.py", line 5, in
NameError: name 'jp' is not defined
问题是,数学.py在那个地方连个文件都没有。是的,但我删除了它,因为我认为Python是在尝试获取它,而不是数学模块。有一个文件叫做数学.pyc在那个位置…是模块吗?为什么它不把它拿来呢。在
谢谢
另外,如何使我刚刚粘贴的部分显示为带有堆栈溢出的代码,而不必为每行按4x空格。在