| | |
Need a bit of Help
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2008
Posts: 8
Reputation:
Solved Threads: 0
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.
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.
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_avgSID: 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.
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
- Hunter S. Thompson
my photography
•
•
Join Date: Oct 2008
Posts: 45
Reputation:
Solved Threads: 6
I wish I had something cool to put here...
•
•
Join Date: Oct 2008
Posts: 8
Reputation:
Solved Threads: 0
•
•
•
•
look here to see how someone else did it.
http://www.daniweb.com/forums/thread...=class+average
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
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 ...
But i guess i'm just to lazy ...
![]() |
Similar Threads
- Identify a 16-bit Program (Windows tips 'n' tweaks)
- Bit Torrent Forum/Site, help? (Website Reviews)
- what is the difference between regular and 64 bit edition (Windows NT / 2000 / XP)
- slow download speeds on bit torrent (IT Professionals' Lounge)
- I would kill for this, just a little bit (C)
- 128 bit encryption (Viruses, Spyware and other Nasties)
- Learn How to Spot a 16-Bit Application (Windows tips 'n' tweaks)
Other Threads in the Python Forum
- Previous Thread: Memory game
- Next Thread: Importing RSS
Views: 592 | Replies: 8
| Thread Tools | Search this Thread |
Tag cloud for Python
anti approximation array avogadro basic beginner builtin cipher clear code color converter countpasswordentry cturtle curved def dictionary drive dynamic examples excel file float format frange ftp function gui homework import input java lapse library line lines linux list lists loop mouse multiple mysqldb mysqlquery newb number numbers output parsing path port prime program programming projects py2exe pygame pymailer pyqt python random raw_input recursion recursive redirect script scrolledtext server singleton sqlite ssh stamp stderr string strings subprocess sum syntax table terminal text textarea thread threading time tkinter tlapse tuple tutorial twoup ubuntu unicode urllib urllib2 variable web-scrape wikipedia windows word wxpython






