Vpython collide

I tried to wite the script about collide running at Jupyter notebook

The script will let the two ball throw together by equal speed.

When they touched together,then each ball will get the opposite speed.

But when I ran the script.

Then the two ball didn't touch,and move toward the distance by -z axis .

How to fix my code?

P.S.

And I will sorry for my English grammer.

But I have attempted to express my problem.

If there is inappropriate to this question.

plz let my know instead of down voting.

I will adjust immediately,thx.

# -*- coding: utf8 -*-
from vpython import *


m1 = 2.0 

x1 = -10.0 

v1= 6.0 

size1 = 1.0

m2 = 1.0 

x2 = 0.0 

v2= 3.0 

size2 = 1.0

Force = 5.0 

spring_L = 5.0 

scene = display(width=1200, height=300, background=(0.5,0.5,0), center=(0,0,0),forward=(0,-0.5,-1),range=30)

ball1 = sphere(radius=size1, color = color.red) 

ball1.pos = vector(x1,0,0) 

ball1.v = vector (v1,0,0)

v1_arrow = arrow(pos=ball1.pos,axis=ball1.v,shaftwidth=0.2*size1 ,color = color.red)

ball2 = sphere(radius=size2, color = color.blue) 

ball2.pos = vector(x2,0,0) 

ball2.v = vector (v2,0,0)

v2_arrow = arrow(pos=ball2.pos,axis=ball2.v,shaftwidth=0.2*size2 ,color = color.red)

spring = helix(pos=ball2.pos, radius=0.5, thickness =0.1) 

spring.coils = 10

spring.axis = vector(-spring_L,0,0)

t = 0 

dt = 0.001 

x_t = graph(x=0,y=300,width=400,height=300, 

title='x-t', xtitle='t', ytitle='x',

foreground=color.black,background=color.white,

xmax=10, xmin=0, ymax=20, ymin=-10)

f1_1 = gcurve(color=color.red)

f1_2 = gcurve(color=color.blue)

v_t = graph(x=400,y=300,width=400,height=300, 

title='vx-t', xtitle='t', ytitle='vx',

foreground=color.black,background=color.white,

xmax=10, xmin=0, ymax=10, ymin=0)

f2_1 = gcurve(color=color.red)

f2_2 = gcurve(color=color.blue)

a_t = graph(x=800,y=300,width=400,height=300, 

title='ax-t', xtitle='t', ytitle='ax',

foreground=color.black,background=color.white,

xmax=10, xmin=0, ymax=10, ymin=-10)

f3_1 = gcurve(color=color.red)

f3_2 = gcurve(color=color.blue)


while True :
    print("ball2.pos.mag {}".format(ball2.pos.mag))
    print("ball1.pos.mag {}".format(ball1.pos.mag))
    rate(1000)
    if abs(ball2.pos.mag - ball1.pos.mag) < spring_L : 

        ball1_a = -1 * Force / m1
        print("ball1_a {}".format(ball1_a))

        ball2_a = 1 * Force / m2
        print("ball2_a {}".format(ball2_a))

        spring.axis = ball1.pos-ball2.pos

    else : 

        ball1_a=0

        ball2_a=0

        spring.axis = vector(-spring_L,0,0)

    ball1.v = ball1.v + vector(ball1_a,0,0) *dt  

    ball2.v = ball2.v + vector(ball2_a,0,0) *dt

    ball1.pos = ball1.pos+ball1.v*dt 

    ball2.pos = ball2.pos+ball2.v*dt 

    v1_arrow.pos = ball1.pos 

    v1_arrow.axis = ball1.v 

    v2_arrow.axis = ball2.v 

    spring.pos=ball2.pos 


t=t+dt