here's what i currently got

# Reading the .csv file

energyFile = open("EnergySources.csv","r")

stateDict = {}
for line in energyFile:
    line = line.strip()
    fields = line.split(",")
    if fields[0] == "State" or fields[0] == "":
    state = fields[0]

    total = fields[-1]
    coal = fields[1]
    naturalgas = fields[2]
    petroleum = fields[3]
    nuclear = fields[4]
    hydroelectric = fields[5]
    biomass = fields[6]
    geothermal = fields[7]
    interstate = fields[8]
    other = fields[9]

for i in range(10):

while True:
    answer= raw_input("Pick a state")
    if answer == "":
    if answer in stateDict:
        print state
        print "Not valid" 


here is the assignment

In this project we will do a data analysis and visualization project, producing maps like the one in the picture above. The map shows millions of BTUs of energy per capits produced by coal in each state in 2007. Why the heck do they burn so much coal in Wyoming?

The data comes from two Web sites. The Energy Information Administration is a Federal agency that keeps statistics on energy. The file we're using comes from their overview page. To correct for the populations of the different states, we'll also use the list of state populations from Wikipedia.

Finally, we'll actually make the map using IBM's Many Eyes visualization service. This cool Web site lets up upload a table of data, and then choose different ways of visualizing it.

The two files we are using are: 
We've taken a preliminary look at both files in class. You do not need to hand in these two files, the TAs will have them when they grade the programs.

Your program should read the data from the two files, and write out a third file, sources.tsv, which you should upload to Many Eyes to make the visualization.

Working in Pairs

You may do this program with a partner. Both you and your partner should hand in the same program. Your partner may be in a different section. Be sure that your program identifies BOTH partners at the top of the file, by name and student ID number. You may do the program by yourself if you want.
If you work with a partner, you should get together, sit down, and work at the same computer. That way you'll both learn the things you'll need to know to pass the tests. If you let your partner do all the work, you will end up failing the midterm (and, probably, your partner will be very annoyed).

Steps in the Project

We'll do this project in eight steps. After the first four, you'll have a program that is partially working, and you will hand that in on Tues, Nov. 3. On Tues. Nov 10, the whole program, together with your map, will be due. We will only grade the whole program, but if you failed to hand in the partial program, it will cost you points, and if you hand in the partial but not the final program, you can get some partial credit.
The basic structure of the program is the two-loop "build a data structure and do something with it" structure we have been considering in the last two lectures. In these steps, I recommend that you print things out as you go along; none of this printing should appear in the final program, but it will help you figure out whether you have the pieces working as you go along.

Step 1: Read in the energy data. Open the file EnergySources.csv, read through it using a for loop (see the example from the 10/26 lecture on the lectures and readings page), print out each line, and then close it.
Step 2: Break each line up and print out first the name of the state, and then each energy source with labels, for instance: 

Alabama: Coal, 888.4; Natuarl Gas, 431.4; ... 

Convert the numbers to floating point before printing them out.
Step 3: Modify your program so that instead of printing out the data it puts it into a dictionary. Use the name of the state as the key, and for the data, have a list containing all the sources of energy, and the total. Have your program print out the dictionary, and check it.
Step 4: Write a loop that lets the user ask questions. Offer the user this menu: 

Pick an energy source:
1: Coal
2: Natural gas
3: Petroleum
4: Nuclear
5: Hydroelectric
6: Biomass
7: Geothermal
8: Interstate imports

Then have them enter the name of a state. In both cases, the program should loop until the user gives a good input.
Step 4: Answer the user's question by looking up the item in the dictionary. Find the list for the requested state, and then the right item in the list.

im creating a program that will use my data and organize it in a way that allow user to input something and come up with the answer. i know that i need to make a dictionary list but im not sure how. can i just get some input of where to go and some help

Start with something like this (Not Tested).

energyFile = open("EnergySources.csv","r")
state_dict = {}
for line in energyFile:
    line = line.strip()
    fields = line.split(",")
    state = fields[0].strip()
    if state == "State":
        ##   you didn't give us any idea where state name comes from
        state_name = fields[???]
        state_dict[state_name] = fields[1:]
    elif not len(state):
        print "this rec has no state", line
        print 'not a "State" record', line

answer = ""
while answer not in state_dict:
    answer= raw_input("Pick a state")
    if answer in state_dict:
        print answer, data_list
        print "     total is %9.2f" % float(data_list[-1])
        print "Not valid"

And for future reference, you will not find many people who will go through a problem with 45 lines to read. State one or two specific problems and you will get better responses.

This article has been dead for over six months. Start a new discussion instead.