Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Part 2
- // Load the data
- #load "one.fsx"
- //task 2
- let groups =
- Data.studs
- |> Seq.map snd
- |> Seq.distinct
- let count g =
- Data.studs |> Seq.filter (snd >> (=)g) |> Seq.length
- let subjects = Data.subjs
- //--------------Part 1--------------------------------------------
- // Print the average grade for each subject
- let countGrade s =
- Data.marks
- |> Seq.filter (fun (x,y,z) -> y = s)
- |> Seq.averageBy(fun (x,y,z) -> float z)
- printfn "Average Grades"
- subjects
- |> Seq.iter (fun (f,s) ->
- printfn "Subject: %s, \t # Average Grade: %1.2f" s (countGrade f))
- //--------------Part 1--------------------------------------------
- // For each group, print the number of students who failed the exam
- let countFailed g =
- Data.marks
- |> Seq.filter (fun (x,y,z) -> z = 2)
- |> Seq.filter (fun (x,y,z) -> (Seq.exists(fun (name,group) -> name = x && group = g) Data.studs) )
- |> Seq.length
- printfn "\nFailed Students in Groups"
- groups
- |> Seq.iter (fun g ->
- printfn "Group: %d, # Failed students: %d" g (countFailed g))
- //--------------Part 1--------------------------------------------
- // Find the number of failing students for each subject
- let countFailedForSubject s =
- Data.marks
- |> Seq.filter (fun (x,y,z) -> y = s)
- |> Seq.filter (fun (x,y,z) -> z = 2)
- |> Seq.length
- printfn "\nFailing Students in Subjects"
- subjects
- |> Seq.iter (fun (f,s) ->
- printfn "Subject: %s, \t # Failed students: %i" s (countFailedForSubject f))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement