Jul-30-2019, 12:17 PM
Good morning, I can really use some helpm
I need to iterate over a list and if the criteria is met, add item to list. Then print list with the values. Here is what I have:
The code up until the end works as expected.
I need to iterate over a list and if the criteria is met, add item to list. Then print list with the values. Here is what I have:
The code up until the end works as expected.
# After reading the data, # a. Print the state with the highest mean Verbal SAT score # b. Print each state that has a mean Math SAT score greater than 500 satfile = open('state_satscores_2004.txt','r') count = 0 SATList = [] for line in satfile: count += 1 textline = line.strip() items = textline.split() SATList.append(items) # print the number of teams read print('Number of Lines:', count) print(SATList) print('\n','\n') state = [] for line in SATList: state.append(line[0]) print('Here is your state list') print(state) print('\n','\n') verbal = [] for line in SATList: verbal.append(line[1]) print('Here is your verbal list') print(verbal) print('\n','\n') math = [] for line in SATList: math.append(line[2]) print('Here is your Math list') print(math) print('\n','\n') max_verbal = max(verbal) max_state = state[verbal.index(max_verbal)] print('The state with the highest mean Verbal SAT score is:',max_state,'With a score of:',max_verbal) print('\n','\n') #THIS IS THE PART I NEED HELP WITH stategrades = [] goodgrades = [] print('Here are your good grades') for i,j in SATList: if math[2] > str(500): stategrades.append(i) goodgrades.append(j) print(stategrades)Thank you for any help!!