Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Oct 2018
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Need help with a project

    Hello,

    Iím learning to code in python for some fun and giggles. Iím woking out of a used class textbook and some course material I got my hands on.

    Iíve got a project Iíve run into a brick wall with of sorts.

    The initial question is as follows:

    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

    I created lists out of each column, making sure the verbal and math columns were numerical. I need to write a loop that identifies each line that has a math score over 500 and list the corresponding state names.


    I have some code written for this already that I can send via PM. And it worked to a point, and then my computer started being stupid. Iím having trouble getting it to list the state names that are above a 500 mean score.

    Can anyone help me with this? Iím at my wits end but I donít want to continue unless I actually know what Iím doing. All work is being done on a Mac, and I need to do this within python itself, not using PANDAS or other toolkits.

    Thanks!!




    Sent from my iPhone using Tapatalk

  2. #2
    Super Moderator vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,437
    Thanks
    3
    Thanked 50 Times in 50 Posts
    Quote Originally Posted by soulesswanderer View Post
    I have some code written for this already that I can send via PM.
    Post your code here so others can respond to and help you.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  3. Users who have thanked vinyl-junkie for this post:

    soulesswanderer (Oct 27th, 2018)

  4. #3
    New to the CF scene
    Join Date
    Oct 2018
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by vinyl-junkie View Post
    Post your code here so others can respond to and help you.
    One minute, Iíll do just that. New to the forums, didnít know what was allowed.


    Sent from my iPhone using Tapatalk

  5. #4
    New to the CF scene
    Join Date
    Oct 2018
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    This is what I’ve got so far (text file attached):

    Code:
    #!/usr/bin/env python
    # coding: utf-8
    
    # In[65]:
    
    
    import os
    os.chdir('/Users/xxx/downloads')
    
    
    # In[66]:
    
    
    satscores = open('state_satscores_2004.txt', 'r') #open SAT scores file as read only
    
    
    # In[67]:
    
    
    satlist = []
    for line in satscores:
         textline=line.strip()
         items = textline.split()
         satlist.append(items)
    
    
    # In[68]:
    
    
    verbal = []
    for line in satlist:
         verbal.append(float(line[1]))
    
    
    # In[69]:
    
    
    verbal = list(map(int, verbal))
    
    
    # In[70]:
    
    
    math = []
    for line in satlist:
         math.append(int(line[1]))
    
    
    # In[71]:
    
    
    print(math)
    type(math)
    
    
    # In[72]:
    
    
    print(verbal)
    type(verbal)
    
    
    # In[73]:
    
    
    maxverb = max(verbal)
    
    
    # In[74]:
    
    
    maxstate= verbal.index(max(verbal))
    state1, verbal1, math1 = satlist[maxstate]
    
    
    # In[75]:
    
    
    print(state1, 'had the highest mean verbal score.')
    
    
    # In[88]:
    
    
    print(satlist[,3])
    
    
    # In[87]:
    
    
    goodmath = [] 
    for state, verbal, math in satlist: #For each line of text store in a string variable named "line", and
        if math[i] >= 500:
            goodmath.append(item)  #add that line to our list of lines.
            print(goodmath)
    
    
    # In[ ]:

    Sent from my iPhone using Tapatalk
    Last edited by VIPStephan; Oct 27th, 2018 at 08:46 PM. Reason: added code BB tags, removed personal info


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •