Adding tuples of lists to a list in python
Question: I don't understand the syntax of adding tuples whose elements are also
elements of a list to another list that encompasses all of the information.

I'm trying to create a trajectory list that contains tuples of flight data of
a projectile during flight. I want to use tuples so that I can see all of the
information for each moment in time.

    
    
    import random
    import math
    
    gg = -9.81 # gravity m/s**2
    tt = 10 **-9 # seconds
    wind = random.randint(-10,10)   # m/s
    
    #position
    x=random.randint(0,100)   # m/s
    
    #projectile
    
    v0 = float(raw_input('Enter the initial velocity (m/s) -> '));
    theta = float(raw_input('Enter the initial launch angle of projectile (degrees) -> '));
    
    theta *= (180/3.14159265359)
    
    xx = [x]
    yy = [.000000000000000000001]
    dz =[v0]
    time = [0];
    
    
    data = ( time, xx, yy, dz)
    traj = [data]
    
    
    while yy[-1] >0:
    
        traj.append ( math.sqrt( (traj[-1][3][-1] * math.sin(theta) + gg * tt)** 2+        (traj[-1][4] * math.cos(theta) -wind) ** 2 ))    # velocity
        traj.append ( traj[-1][2][-1] + dz[-1] * math.sin(theta) * tt + .5* gg * tt)    # y position
        traj.append ( traj[-1][1][-1] * dz[-1] * math.cos(theta) - wind * tt)    # x position
        traj.append ( traj[-1][0][-1] + tt)     # time
    
    
    print traj
    

Edit: I would input integers for the initial angle and velocity (i.e.-45,45).
Expected outputs would be a list of tuples containing four elements
corresponding to the time, x coordinate, y coordinate, and velocity,
respectively. Currently, I'm receiving a tuple index out of range error.


Answer: Where you have

    
    
    traj[-1][4]
    

in your first `traj.append` line, `traj[-1]` is `data`, and `data` is only
four elements long, so the last item is at index 3.

