朋友你好錯誤消息
在我的信息學研究我運行這個程序,遇到一個錯誤,而通過SSH連接:
'''
a*x**2 + b*x + c = 0
roots(a, b, c)
returns floats when real solution, or complex when complex solution.
'''
#the code for the function
def roots(a, b, c):
"""The root(a, b, c) function solves x for a quadratic equation:
a*x**2 + b*x + c = 0
"""
from numpy.lib.scimath import sqrt
x1 = (-b + sqrt((b)**2 - 4.*a*c))/(2.*a)
x2 = (-b - sqrt((b)**2 - 4.*a*c))/(2.*a)
return x1, x2
要簡單地測試這個功能我已經做了測試功能的程序包括:
#test functions for float and complex numbers
def test_roots_float():
"""Tests the function root(a, b, c) for floats.
Returns True if the function works for floats.
"""
ax1 = 0.0 #known solution for x1
ax2 = -1.0 #known solution for x2
x1, x2 = roots(2, 2, 0) #solve for known solution
if abs(ax1 - x1) == 0 and abs(ax2 - x2) == 0: #test
return True
return False
def test_roots_complex():
"""Tests the function root(a, b, c)
for complex numbers. Returns True if the
function works for complex solutions.
"""
ax1 = (-0.5+0.5j) #known solution for x1
ax2 = (-0.5-0.5j) #known solution for x2
x1, x2 = roots(2, 2, 1) #solve for known solution
if abs(ax1 - x1) == 0 and abs(ax2 - x2) == 0: #test
return True
return False
#run
print 'Test results:'
#test run for floats
test1 = test_roots_float()
if test1:
test1 = 'works'
print 'The function roots(a, b, c) %s for float type\
solutions.' % test1
#test run for complex
test2 = test_roots_complex()
if test2:
test2 = 'works'
print 'The function roots(a, b, c) %s for complex\
type solutions.' % test2
該項目工程,同時運行良好
... ImportError: libifport.so.5: cannot open shared object file: No such file or directory
這是什麼錯誤:當地一所大學的計算機上,但後來也有一些是在導入模塊時,在通過SSH連接發生了什麼? 有沒有解決方案?
原來自己可以指定由包括路徑,當我運行程序要使用的Python或我可以使用[shebang行](http://stackoverflow.com/questions/15587877/run-a-python-腳本的終端內,而無需最Python的命令/ 15588070#15588070) – vardaasen 2015-10-01 00:54:41