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

Page 1 of 1

## 1 Replies - 929 Views - Last Post: 29 September 2012 - 04:43 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=293643&amp;s=aedcf14a0d50b53bd629a0336721bf3f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Eloy04

• New D.I.C Head

Reputation: 0
• 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')
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
for hw_line in NamesSorted_list:

```

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

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

Reputation: 5837
• Posts: 12,681
• 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
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