02-20-06 07:48 AM
Adam wrote:
> Hi,
> I'm trying to write a shell which will assess a list of student's
> grades. The data file consists of the following...
>
> 2068344
> 8
> 6
> 3
> 8
> 2
> 8
> 2068943
> 9
> 7
> 3
> 7
> 3
> 7
>
> The large numbers being the student ID, the small numbers being the
> mark on a certain question.
>
> My overall target is to output the student ID and the overall
> percentage.
> i.e.
> 2068344 78%
> 2068943 47%
>
> I have run into a problem in that when performing the mathematics on
> the file (at this stage the addition of the marks, leading to working
> out the percentage), I can not dfferentiate between each individual
> student, leaving me with one very large and useless number.
>
> Any help on the matter would be brilliant.
>
> Thank you.
Ruby:
Max_score = 10
a = []
while s=gets
if s =~ /\d{7}/
a << [ s.strip ]
else
a.last << s.to_f
end
end
a.each{ |x|
printf "%s %0.1f%%\n", x.shift,
x.inject{|sum,i|sum + i}/(Max_score*x.size)*100
}
[ Post a follow-up to this message ]
|