1 Replies - 810 Views - Last Post: 29 September 2012 - 04:43 PM Rate Topic: -----

#1 Eloy04  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 29-September 12

I'm trying to write a program to calculate the average grade

Posted 29 September 2012 - 12:47 PM

Joe HM3 83 HM2 39 HM4 90 HM1 85
Chris HM2 85 HM5 70 HM1 70
Doug HM1 80 HM3 94 HM2 93 HM4 75
Matt HM4 25 HM1 30
Ricardo HM3 80 HM1 90 Test1  90


I have to alphabetize the names and sort the grades by HM number from 1 to 4, ignoring all other grades. If they don't have a HM number then its a zero. I am stuck on sorting the grades from HM1 to HM4
readfile=open('studentgrades.txt','r')
readfile1_list=readfile.readlines()
NamesSorted_list=sorted(readfile1_list)
NumberOfNames_int=len(NamesSorted_list)

#for info in NamesSorted_list:
#    names_str=info.split()[0]
#    print names_str+' y'
#    if 'HM3' not in NamesSorted_list[2].split():
#        print 0
name1grades_list=[]
for hw_line in NamesSorted_list:
    namegrade_list=hw_line.split()
    for grades in namegrade_list:
        print grades



Ive have tried googleing how sort grades by name.

Is This A Good Question/Topic? 0
  • +

Replies To: I'm trying to write a program to calculate the average grade

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5535
  • View blog
  • Posts: 11,857
  • Joined: 02-June 10

Re: I'm trying to write a program to calculate the average grade

Posted 29 September 2012 - 04:43 PM

Quote

Ive have tried googleing how sort grades by name.

You're never going to find EXACT matches to such things. Your going to have to open up your search parameters and do some thinking so you can apply general sorting concepts to your data.

I mean, think about it. Do you really think there is a ton of requests for this exact sort from a course homework asignment? Is it really any different to sort names, grades, or the makes of automobiles?

This is where you the software engineer need to actually ENGINEER a solution.

Take the one example:
1 Joe HM3 83 HM2 39 HM4 90 HM1 85

Parse the line to an object with meaning:
name property: Joe
Grades[,] array:
HM3,83
HM2,39
HM4,90
HM1,85

Now sort the array by the first element

Taa Daa...

This post has been edited by tlhIn`toq: 29 September 2012 - 04:44 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1