(D,x1,x2)=root2(1.,-2.,-3.) #以元組方式傳回
print('a,b,c=',a,b,c)
if(D > 0): print('兩實根=',(x1,x2)) #列印元組
else:
print('D < 0, D=',D)
print('兩複數根=',x1,x2)
print(' ')
a,b,c=1.,-2.,3.
(D,x1,x2)=root2(1.,-2.,3.) #以元組方式傳回
print('a,b,c=',a,b,c)
if(D > 0): print('兩實根=',(x1,x2)) #列印元組
else:
print('D < 0, D=',D)
print('兩複數根=',x1,x2)
Web VPython 3.2
# filepath: https://physexp.thu.edu.tw/~AP/YC/NUM/HTML/mag-bottle-tr.txt
f = read_local_file(scene.title_anchor)
print(f.name) # The file name
print(f.size) # File size in bytes
print(f.type) # What kind of file
print(f.date) # Creation date if available
print('-------------------')
#print(f.text) # The file contents
f=f.text
print(type(a))
a=a.strip()
a2=a.split(' ')
b=list(a2)
#print(b)
print('len(b)=',len(b),type(b),type(b[0]),b[0])
for i in range(len(b)):
b[i]=float(b[i])
def traject(b):
ball = sphere(radius = 0.1, color=vec(1,1,0),make_trail=True, retain=100)
Nb=len(b)
#print('Nb=',Nb)
N=Nb/4
t=[float(b[i*4+0]) for i in range(N)]
x=[float(b[i*4+1]) for i in range(N)]
y=[float(b[i*4+2]) for i in range(N)]
z=[float(b[i*4+3]) for i in range(N)]
LX=max(x)
LY=max(y)
LZ=max(z)
sw=LX/100.
arrX=arrow(pos=vec(0,0,0),axis=vec(LX,0,0),shaftwidth=sw,color=vec(1,0,0))
arrY=arrow(pos=vec(0,0,0),axis=vec(0,LY,0),shaftwidth=sw,color=vec(0,1,0))
arrZ=arrow(pos=vec(0,0,0),axis=vec(0,0,LZ),shaftwidth=sw,color=vec(0,0,1))
ball.pos=vec(x[0],y[0],z[0])
for i in range(N):
rate(10)
ball.pos=vec(x[i],y[i],z[i])
#print(t[i],x[i],y[i],z[i])
scene = canvas(width=800, height=800, center=vec(0,0,0),background=vec(0,0,0))
print('====',type(b))
traject(b)