を使用,
すると、複数のprint
ステートメントを同じ行に書き込むことができます。
print 'hello',
print 'world'
問題:関数によって返された値を出力するとき、複数の関数呼び出しによって返された値を同じ行に出力するにはどうすればよいですか?
次のコードは、各関数によって返された値を別の行に出力します。
import math
def square_root(a):
x = a
e = 0.0000001
while True:
print x
y = (x + a/x)/2
if( abs(x - y) < e ):
return x
x = y
def test_square_root():
for i in range(1,10):
print float(i),
print square_root(float(i)),
print math.sqrt(float(i)),
print abs( square_root(float(i)) - math.sqrt(float((i))) )
test_square_root()