Hello, I and doing a ball bounce project for Vpython and I am trying run the program I wrote. I keep getting an invalid syntax error, but I am unable to find any. Please help.

from visual import*
wallA = box(pos=vector(0,6,0), size=vector(12.1,0.2,12.1), color=color.red)
wallB = box(pos=vector(0,-6,0), size=vector(12.1,0.2,12.1), color=color.green)
wallC = box(pos=vector(6,0,0), size=vector(0.2,12.1,12.1), color=color.yellow)
wallD = box(pos=vector(-6,0,0), size=vector(0.2,12.1,12.1), color=color.yellow)
wallE = box(pos=vector(0,0,-6), size=vector(12.1,12.1,0.2), color=color.yellow)


ball=sphere(pos=vector(0,0,0), radius=0.20, color=color.white)
ball.vel=vector(1.5,-.9,-1.9)
vscale=3.0

dt=0.01

velarrow=arrow(pos=ball.pos, axis=ball.vel, color=color.blue)
ball.trail=curve(pos=[ball.pos], color=color.white)


t=0

scene.autoscale=false

while t<10:
    rate(1/dt)
    t=t+dt
    
    if ((ball.pos.y-ball.radius+ball.vel.y*dt)<wallB.pos.y+0.5*wallB.height):
        ddt=(wallB.pos.y+0.5*wallB.height-ball.pos.y+ball.radius)/ball.vel.y
        ball.pos=ball.pos+ball.vel*ddt
        ball.trail.append(ball.pos)
        ball.vel.y=-ball.vel.y
        ball.pos=ball.pos+ball.vel*(dt-ddt)
    else:
        ball.pos=ball.pos+ball.vel*dt

    if ((ball.pos.y+ball.radius+ball.vel.y*dt)>wallA.pos.y-0.5*wallA.height):
        ddt=(wallA.pos.y-0.5*wallA.height-ball.pos.y-ball.radius)/ball.vel.y
        ball.pos=ball.pos+ball.vel*ddt
        ball.trail.append(ball.pos)
        ball.vel.y=-ball.vel.y
        ball.pos=ball.pos+ball.vel*(dt-ddt)
    else:
        ball.pos=ball.pos+ball.vel*dt

    if ((ball.pos.x+ball.radius+ball.vel.x*dt)>wallC.pos.x-0.5*wallC.length):
        ddt=(wallC.pos.x-0.5*wallC.length-ball.pos.x-ball.radius)/ball.vel.x
        ball.pos=ball.pos+ball.vel*ddt
        ball.trail.append(ball.pos)
        ball.vel.x=-ball.vel.x
        ball.pos=ball.pos+ball.vel*(dt-ddt)
    else:
        ball.pos=ball.pos+ball.vel*dt

    if ((ball.pos.x-ball.radius+ball.vel.x*dt)<wallD.pos.x+0.5*wallD.length):
        ddt=(wallD.pos.x+0.5*wallD.length-ball.pos.x+ball.radius)/ball.vel.x
        ball.pos=ball.pos+ball.vel*ddt
        ball.trail.append(ball.pos)
        ball.vel.x=-ball.vel.x
        ball.pos=ball.pos+ball.vel*(dt-ddt)
    else:
        ball.pos=ball.pos+ball.vel*dt

    if ((ball.pos.z-ball.radius+ball.vel.z*dt)<wallE.pos.z+0.5*wallE.width):
        ddt=(wallE.pos.z+0.5*wallE.width-ball.pos.z+ball.radius)/ball.vel.z
        ball.pos=ball.pos+ball.vel*ddt
        ball.trail.append(ball.pos)
        ball.vel.z=-ball.vel.z
        ball.pos=ball.pos+ball.vel*(dt-ddt)
    else:
        ball.pos=ball.pos+ball.vel*dt

    if ((ball.pos.z+ball.radius+ball.vel.z*dt)>(-wallE.pos.z)-0.5*wallE.width):
        ddt=((-wallE.pos.z)-0.5*wallE.width-ball.pos.z-ball.radius)/ball.vel.z
        ball.pos=ball.pos+ball.vel*ddt
        ball.trail.append(ball.pos)
        ball.vel.z=-ball.vel.z
        ball.pos=ball.pos+ball.vel*(dt-ddt)
    else:
        ball.pos=ball.pos+ball.vel*dt

    ball.pos=ball.pos+ball.vel*dt
    velarrow.pos=ball.pos
    velarrow.axis=ball.vel
    ball.trail.append(ball.pos)
    
  
print "End of program. Ending time is ", t,"seconds."
print "Final Position of ball is ", ball.pos,"."
from visual import*
wallA = box(pos=vector(0,6,0), size=vector(12.1,0.2,12.1), color=color.red)
wallB = box(pos=vector(0,-6,0), size=vector(12.1,0.2,12.1), color=color.green)
wallC = box(pos=vector(6,0,0), size=vector(0.2,12.1,12.1), color=color.yellow)
wallD = box(pos=vector(-6,0,0), size=vector(0.2,12.1,12.1), color=color.yellow)
wallE = box(pos=vector(0,0,-6), size=vector(12.1,12.1,0.2), color=color.yellow)


ball=sphere(pos=vector(0,0,0), radius=0.20, color=color.white)
ball.vel=vector(1.5,-.9,-1.9)
vscale=3.0

dt=0.01

velarrow=arrow(pos=ball.pos, axis=ball.vel, color=color.blue)
ball.trail=curve(pos=[ball.pos], color=color.white)


t=0

scene.autoscale=false

while t<10:
    rate(1/dt)
    t=t+dt
    
    if ((ball.pos.y-ball.radius+ball.vel.y*dt)<wallB.pos.y+0.5*wallB.height):
        ddt=(wallB.pos.y+0.5*wallB.height-ball.pos.y+ball.radius)/ball.vel.y
        ball.pos=ball.pos+ball.vel*ddt
        ball.trail.append(ball.pos)
        ball.vel.y=-ball.vel.y
        ball.pos=ball.pos+ball.vel*(dt-ddt)
    else:
        ball.pos=ball.pos+ball.vel*dt

    if ((ball.pos.y+ball.radius+ball.vel.y*dt)>wallA.pos.y-0.5*wallA.height):
        ddt=(wallA.pos.y-0.5*wallA.height-ball.pos.y-ball.radius)/ball.vel.y
        ball.pos=ball.pos+ball.vel*ddt
        ball.trail.append(ball.pos)
        ball.vel.y=-ball.vel.y
        ball.pos=ball.pos+ball.vel*(dt-ddt)
    else:
        ball.pos=ball.pos+ball.vel*dt

    if ((ball.pos.x+ball.radius+ball.vel.x*dt)>wallC.pos.x-0.5*wallC.length):
        ddt=(wallC.pos.x-0.5*wallC.length-ball.pos.x-ball.radius)/ball.vel.x
        ball.pos=ball.pos+ball.vel*ddt
        ball.trail.append(ball.pos)
        ball.vel.x=-ball.vel.x
        ball.pos=ball.pos+ball.vel*(dt-ddt)
    else:
        ball.pos=ball.pos+ball.vel*dt

    if ((ball.pos.x-ball.radius+ball.vel.x*dt)<wallD.pos.x+0.5*wallD.length):
        ddt=(wallD.pos.x+0.5*wallD.length-ball.pos.x+ball.radius)/ball.vel.x
        ball.pos=ball.pos+ball.vel*ddt
        ball.trail.append(ball.pos)
        ball.vel.x=-ball.vel.x
        ball.pos=ball.pos+ball.vel*(dt-ddt)
    else:
        ball.pos=ball.pos+ball.vel*dt

    if ((ball.pos.z-ball.radius+ball.vel.z*dt)<wallE.pos.z+0.5*wallE.width):
        ddt=(wallE.pos.z+0.5*wallE.width-ball.pos.z+ball.radius)/ball.vel.z
        ball.pos=ball.pos+ball.vel*ddt
        ball.trail.append(ball.pos)
        ball.vel.z=-ball.vel.z
        ball.pos=ball.pos+ball.vel*(dt-ddt)
    else:
        ball.pos=ball.pos+ball.vel*dt

    if ((ball.pos.z+ball.radius+ball.vel.z*dt)>(-wallE.pos.z)-0.5*wallE.width):
        ddt=((-wallE.pos.z)-0.5*wallE.width-ball.pos.z-ball.radius)/ball.vel.z
        ball.pos=ball.pos+ball.vel*ddt
        ball.trail.append(ball.pos)
        ball.vel.z=-ball.vel.z
        ball.pos=ball.pos+ball.vel*(dt-ddt)
    else:
        ball.pos=ball.pos+ball.vel*dt

    ball.pos=ball.pos+ball.vel*dt
    velarrow.pos=ball.pos
    velarrow.axis=ball.vel
    ball.trail.append(ball.pos)
    
  
print "End of program. Ending time is ", t,"seconds."
print "Final Position of ball is ", ball.pos,"."

This code works just fine with vpython and python27. What is your exact traceback error message?

I kept getting a syntax error message, once I deleted the print lines:

print "End of program. Ending time is ", t,"seconds."
print "Final Position of ball is ", ball.pos,"."

it was able to run

I like the improved version of the IDLE editor that comes with Vpython.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.