Need a bit of Help

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2008
Posts: 8
Reputation: BmeEng is an unknown quantity at this point 
Solved Threads: 0
BmeEng BmeEng is offline Offline
Newbie Poster

Need a bit of Help

 
0
  #1
Oct 29th, 2008
Hi folks,
I'm learning python this year, and I need a bit of help on an assignment.
My program is supposed to be able to read from a file, which contains student numbers and their scores and it is supposed to compute their individual averages and the class average and then assign a grade based upon that.

I'm stuck on successfully calculating the true class average and comparing that value to the individual averages of each student. Specifically, the sum of the student averages seems to be the problem.

Here is what I have so far and the output. The output shows the main problem.

sum = 0
count = 0
avg_sum = 0
file = open("scores.txt","r")
lines = file.readlines()
line_count = len(lines)
file.close()
for line in lines:
    scores = line.split()
    count = 0
    sum = 0.0
    for score in scores:
        if count != 0:
            x = int(score)
            sum = sum + x
            count = count + 1
        else:
            count = count + 1
    count = count - 1
    if count !=0:
        avg = int(sum/count)
    else:
        avg = 0
    avg_sum = avg_sum + avg
    class_avg = int(avg_sum/line_count)
    if(avg >= class_avg):
        print "SID:", scores[0], "Average:", avg, "Grade: P", "class average sum:", avg_sum, "class average:", class_avg
    else:
        print "SID:", scores[0], "Average:", avg, "Grade: NP", "class average sum:", avg_sum, "class average:", class_avg
print "Class Average:", class_avg

SID: 1001 Average: 0 Grade: P class average sum: 0 class average: 0
SID: 1002 Average: 90 Grade: P class average sum: 90 class average: 11
SID: 1003 Average: 100 Grade: P class average sum: 190 class average: 23
SID: 1004 Average: 20 Grade: NP class average sum: 210 class average: 26
SID: 1005 Average: 80 Grade: P class average sum: 290 class average: 36
SID: 1006 Average: 70 Grade: P class average sum: 360 class average: 45
SID: 1007 Average: 13 Grade: NP class average sum: 373 class average: 46
SID: 1008 Average: 70 Grade: P class average sum: 443 class average: 55
Class Average: 55

Any guidance would be appreciated.
Last edited by BmeEng; Oct 29th, 2008 at 11:44 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,297
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 178
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: Need a bit of Help

 
0
  #2
Oct 29th, 2008
This old horse of homework has come up a fair number of times here. Maybe you ought to search for it. Don't forget to use code tags so we can actually read what you are doing so far.
Last edited by sneekula; Oct 29th, 2008 at 11:21 pm.
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 489
Reputation: shadwickman will become famous soon enough shadwickman will become famous soon enough 
Solved Threads: 76
shadwickman's Avatar
shadwickman shadwickman is offline Offline
Posting Pro in Training

Re: Need a bit of Help

 
0
  #3
Oct 29th, 2008
Can you please put your code in python CODE tags so it has syntax highlighting, but most importantly indentation. Seeing as Python requires indentation, and the above has none, it's hard to sort through at the moment.
"Two good old boys in a fire-apple red convertible. Stoned. Ripped. Twisted. Good people."
- Hunter S. Thompson

my photography
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 8
Reputation: BmeEng is an unknown quantity at this point 
Solved Threads: 0
BmeEng BmeEng is offline Offline
Newbie Poster

Re: Need a bit of Help

 
0
  #4
Oct 29th, 2008
Fixed. Sorry about that. Took me awhile to find the code tags button.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 45
Reputation: tyincali is an unknown quantity at this point 
Solved Threads: 6
tyincali tyincali is offline Offline
Light Poster

Re: Need a bit of Help

 
0
  #5
Oct 29th, 2008
look here to see how someone else did it.

http://www.daniweb.com/forums/showth...=class+average
I wish I had something cool to put here...
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 8
Reputation: BmeEng is an unknown quantity at this point 
Solved Threads: 0
BmeEng BmeEng is offline Offline
Newbie Poster

Re: Need a bit of Help

 
0
  #6
Oct 29th, 2008
Originally Posted by tyincali View Post
look here to see how someone else did it.

http://www.daniweb.com/forums/thread...=class+average
I get 404 File Not Found
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 45
Reputation: tyincali is an unknown quantity at this point 
Solved Threads: 6
tyincali tyincali is offline Offline
Light Poster

Re: Need a bit of Help

 
0
  #7
Oct 29th, 2008
huh, just search for "class average" you'll find something to help you.
I wish I had something cool to put here...
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 39
Reputation: mathijs is an unknown quantity at this point 
Solved Threads: 2
mathijs's Avatar
mathijs mathijs is offline Offline
Light Poster

Re: Need a bit of Help

 
0
  #8
Oct 30th, 2008
The problem with the link is that it highlits the words class and average and for some reason that doesn't work but if you just remove that part you do get to the right page.
http://www.daniweb.com/forums/thread66974.html
I could fill this thing with great stories and magical experiences.
But i guess i'm just to lazy ...
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 8
Reputation: BmeEng is an unknown quantity at this point 
Solved Threads: 0
BmeEng BmeEng is offline Offline
Newbie Poster

Re: Need a bit of Help

 
0
  #9
Nov 4th, 2008
Thanks to all those who replied. I eventually figured it out though!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum


Views: 592 | Replies: 8
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC