I'm working on the below problem: For this question, you are to write a program that reads the data in the file state_satscores_2004.txt. Each line of this file has name of a state, mean Verbal SAT score, and mean Math SAT score. 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 Submit the code and the output from your program. I am currently working on the first part, but keep receiving an error that states: File "StateSATScores.py", line 10, in max_score = max(meanverbalscore) ValueError: max() arg is an empty sequence Here is my code: StateSATScores = open('state_satscores_2004.txt', 'r') StateSATScores = [] for line in StateSATScores: textline=line.strip() items = textline.split() StateSATScores.append(items) meanverbalscore = [] for line in StateSATScores: meanverbalscore.append(int(line[1])) max_score = max(meanverbalscore) print('The highest mean Verbal SAT score was: ', max_score) state, verbal, math = StateSATScores[0] meanmathscore = [] for (state, verbal, math) in StateSATScores: meanmathscore.append(int(line[1])) states = [] for(state, verbal, math) in StateSATScores: states.append(state) I've saved it as a .py and tried running and receive that error. Can you confirm why it's getting that error and what needs to be changed to fix and to code it appropriately? For the second question I want to confirm how to code as well. Below is the info that is in the state_satscores_2004.txt file.
New_York 497 510
Connecticut 515 515
Massachusetts 518 523
New_Jersey 501 514
New_Hampshire 522 521
D.C. 489 476
Maine 505 501
Pennsylvania 501 502
Delaware 500 499
Georgia 494 493
Rhode_Island 503 502
Virginia 515 509
North_Carolina 499 507
Maryland 511 515
Florida 499 499
Vermont 516 512
Indiana 501 506
South_Carolina 491 495
Hawaii 487 514
Oregon 527 528
Alaska 518 514
Texas 493 499
Washington 528 531
California 501 519
Nevada 507 514
Arizona 523 524
Montana 537 539
Ohio 538 542
Colorado 554 553
Idaho 540 539
West_Virginia 524 514
Tennessee 567 557
New_Mexico 554 543
Kentucky 559 557
Wyoming 551 546
Michigan 563 573
Illinois 585 597
Minnesota 587 593
Alabama 560 553
Kansas 584 585
Louisiana 564 561
Missouri 587 585
Nebraska 569 576
Oklahoma 569 566
Wisconsin 587 596
Utah 565 556
Arkansas 569 555
Iowa 593 602
South_Dakota 594 597
Mississippi 562 547
North_Dakota 582 601
"""
Python version : 3.6
Python program to read data from input file and display output of
queries
"""
# open the file in read mode
StateSATScoresFile = open('state_satscores_2004.txt', 'r')
# create an empty list to store list of 3 items i.e state name,
mean Verbal SAT score and mean Math SAT score
StateSATScores = []
# loop to read file line by line and append the data into the
list
for line in StateSATScoresFile:
# remove leading and trailing space from line
textline=line.strip()
# split the data into list of strings
items = textline.split()
StateSATScores.append(items) # append the list into
list
# Print the state with the highest mean Verbal SAT score
# initialize max_verbal_score to 0 and max_verbal_score_state to
empty string
max_verbal_score = 0
max_verbal_score_state = ''
# loop over the list
for line in StateSATScores:
score = (int(line[1])) # convert the mean verbal score
from string to int
# max_verbal_score is not set or max_verbal_score <
score, update max_verbal_score and max_verbal_score_state
if max_verbal_score_state == '' or max_verbal_score
< score:
max_verbal_score_state =
line[0]
max_verbal_score = score
# display the state with max verbal score and the state
print(max_verbal_score_state, 'has the highest mean Verbal SAT
score of', max_verbal_score)
# Print each state that has a mean Math SAT score greater than
500
states = [] # create an empty list of states
# loop over the list
for line in StateSATScores:
# convert mean Math score from string to int
score = int(line[2])
# score > 500, append the state name to list of
states
if score > 500:
states.append(line[0])
# display the states with max SAT score > 500
print('\nStates that has a Math SAT score greater than 500: ',
states)
#end of program
Code Screenshot:
Output:
Input file:
Output:
Get Answers For Free
Most questions answered within 1 hours.