I´ve been trying to print 2 vectors in a table-like format. The trouble comes when elements from list A and list B don´t have the same ammount of floats
import math
def f(x):
y=1/(math.sqrt(1+x))
return y
xmin=0.0
xmax=1.0
print "Write some n:"
n=input()
x=[]
delta=((xmax-xmin)/n)
for i in range (n):
xx=xmin+i*delta
x.append(xx)
y=[]
b=f(x[0])
y.append(b)
for i in range (1,n-1):
yy=2*f(x[i])
y.append(yy)
y.append(f(x[n-1]))
for i in range(n):
print x[i],y[i]
The problems comes when printing the last line: What I want:
0.0 1.0
0.125 1.88561808316
0.25 1.788854382
What I get:
0.0 1.0
0.125 1.88561808316
0.25 1.788854382
How can I fix those digits, so the program prints the result properly? Thanks :)