Question

I'm working on the below problem: For this question, you are to write a program that...

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  

Homework Answers

Answer #1

"""
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:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Is the math SAT score correlated with verbal SAT scores? J. What would you predict the...
Is the math SAT score correlated with verbal SAT scores? J. What would you predict the math SAT score would be for a state which has a verbal SAT score of 510? STATE Mean SAT I Verbal Mean  SAT I Math 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...
Construct a scatter plot diagram for the variables SAT Verbal and SAT Math and then using...
Construct a scatter plot diagram for the variables SAT Verbal and SAT Math and then using your scatterplot do the variables appear to be positively, negatively or not related at all? STATE MEAN SAT Verbal MEAN SAT Math NY 497 510 Conn 515 515 Mass 518 523 NJ 501 514 NH 522 521 D.C. 489 476 Maine 505 501 Penn 501 502 Delaware 500 499 Georgia 494 493 RI 503 502 Virginia 515 509 NC 499 507 Maryland 511 515...
You may need to use the appropriate technology to answer this question. The College Board provided...
You may need to use the appropriate technology to answer this question. The College Board provided comparisons of Scholastic Aptitude Test (SAT) scores based on the highest level of education attained by the test taker's parents. A research hypothesis was that students whose parents had attained a higher level of education would on average score higher on the SAT. The overall mean SAT math score was 514.† SAT math scores for independent samples of students follow. The first sample shows...
Describe what distribution we use when calculating test statistics Z OR T STATİSTİCS? STATE ORDER2019 ORDER2018...
Describe what distribution we use when calculating test statistics Z OR T STATİSTİCS? STATE ORDER2019 ORDER2018 Alabama 536 559 Alaska 487 514 Arizona 499 523 Arkansas 554 562 California 499 498 Colorado 556 539 Connecticut 513 509 Delaware 476 501 Florida 471 498 Georgia 473 491 Hawaii 469 486 Idaho 517 543 Illinois 591 576 Indiana 475 499 Iowa 575 593 Kansas 563 577 Kentucky 563 550 Louisiana 546 564 Maine 453 506 Maryland 491 508 Massachusetts 509 511 Michigan...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
3. (Exercises 8.11, 8.20, using R) (3 pt) Cooling method for gas turbines. Refer to the...
3. (Exercises 8.11, 8.20, using R) (3 pt) Cooling method for gas turbines. Refer to the Journal of Engineering for Gas Turbines and Power (January 2005) study of a high-pressure inlet fogging method for a gas turbine engine. We now consider the interaction model for heat rate (y) of a gas turbine as a function of cycle speed (x1) and cycle pressure ratio (x2), E(y) = β0 + β1x1 + β2x2 + β3x1x2. Import the data from the file “GASTURBINE.txt”...
Your firm works in construction and buys ASTM A325M8S bolts in very large numbers. You are...
Your firm works in construction and buys ASTM A325M8S bolts in very large numbers. You are interested in purchasing bolts from different suppliers and have obtained and tested samples of 200 bolts from three suppliers: Allnutt, Boltzman, Coachers.You have tested these in your new bolt testing machine, purchased after you had discovered your old bolt testing machine was performing erratically. (For the purposes of this question, you are safe to assume that the new machine works perfectly and that its...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT