PYTHON 3: Read a file and map the coordinates to the turtle screen
Question: So I have to write a program that reads a `csv` file which contains earthquake
data, it then takes only the latitude and longitude from the file and map it
to the turtle screen in Python 3.

This is the [CSV file](http://textuploader.com/gayg)

My program:

    
    
    import turtle
    def drawQuakes():
     filename = input("Please enter the quake file: ")
     readfile = open(filename, "r")
     readlines = readfile.read()
    
     start = readlines.find("type")
     g = readlines[start]
     Type = g.split(",")
     tracy = turtle.Turtle()
     tracy.up()
     for points in Type:
         print(points)
         x = float(Type[1])
         y = float(Type[2])
         tracy.goto(x,y)
         tracy.write(".")
    drawQuakes()
    

I know this program is fairly easy, but I keep getting this error:

    
    
    x = float(Type[1])IndexError: list index out of range
    


Answer: You aren't using the file correctly, let's break it down:

    
    
    readlines = readfile.read()
    # readlines is now the entire file contents
    
    start = readlines.find("type")
    # start is now 80
    
    g = readlines[start]
    # g is now 't'
    
    Type = g.split(",")
    # Type is now ['t']
    
    tracy = turtle.Turtle()
    tracy.up()
    for points in Type:
        print(points)
        # points is 't'
    
        x = float(Type[1])
        # IndexError: list index out of range
    
        y = float(Type[2])
        tracy.goto(x,y)
        tracy.write(".")
    

I would use the csv.DictReader:

    
    
    import turtle
    import csv
    
    def drawQuakes():
        filename = input("Please enter the quake file: ")
    
        tracy = turtle.Turtle()
        tracy.up()
    
        with open(filename, 'r') as csvfile:
            reader = reader = csv.DictReader(csvfile)
            for row in reader:
                if row['type'] == 'earthquake':
                    x = float(row['latitude'])
                    y = float(row['longitude'])
                    tracy.goto(x,y)
                    tracy.write(".")
    
    drawQuakes()
    

![enter image description here](http://i.stack.imgur.com/pCBu8.png)

