# Program to find representative from district
# Builds a list of names of representatives, repList
# repList[district-1] should be the name of the
# representative from district. 

repList = [] # Start with empty list; we'll fill it from file
repFile = open('CAreps.txt','r')
line = repFile.readline()  # Read first line of file
while line != '':  # line = '' means file is over
    # process line of data
    words = line.split()  # Break up line into list of words
    name = '' # Variable will eventually contain name of representative
    # len(words) is length of list words
    # range(len(words)) is the list of positions in list words
    for i in range(len(words)):  
        if i >= 2: # positions 0 and 1 are not part of the name
            name = name + ' ' + words[i]  # other positions are
    # name now contains a single string, the name
    # [name] is a list containing one item, the name
    # We concatenate the two lists together
    repList = repList +[name]
    line = repFile.readline()
repFile.close() # We're done with the file; we have the data. 

reply = 'Garbage' # Before anything has been entered
while reply != '':
    reply = raw_input('Enter district or enter to quit: ')
    if reply != '':
        district = int(reply)
        name = repList[district-1]
        print 'The representative in district',district,'is',name




