Student Marks Manager
Start with Student Marks Manager
Learn student marks manager through an executable example, then connect the small demonstration to production code.
What you’ll learn
- Explain the main purpose of student marks manager.
- Read and run the complete Go example in this lesson.
- Apply the concept and recognize common mistakes.
Understand the idea
Represent students as structs, calculate totals and averages, then classify results by clear thresholds. Keep grading logic in a function so it can be tested independently of input or output code.
This program evaluates two students with fixed marks to demonstrate the processing workflow.
Visualize how it works
Follow this diagram before executing the example. Check where a value or decision changes what runs next.
Tools, syntax and practical notes
Expansion: add a persistent JSON or SQL store, import/export, grading-policy configuration, validation and table-driven tests. Specify whether averages are weighted and how ties are handled.
Run a complete Go example
This example is a complete program. Save it as main.go or paste it into the Go Playground.
Go code
package main
import "fmt"
type Student struct {
Name string
Marks []int
}
func average(marks []int) float64 {
if len(marks) == 0 {
return 0
}
sum := 0
for _, mark := range marks {
sum += mark
}
return float64(sum) / float64(len(marks))
}
func grade(avg float64) string {
if avg >= 75 {
return "A"
}
if avg >= 50 {
return "B"
}
return "C"
}
func main() {
students := []Student{{"Asha", []int{80, 90, 70}}, {"Ravi", []int{55, 60, 50}}}
for _, s := range students {
avg := average(s.Marks)
fmt.Printf("%s average %.1f grade %s\n", s.Name, avg, grade(avg))
}
}
Output
Asha average 80.0 grade A
Ravi average 55.0 grade BTrace what the program does
Asha has an average of 80 and grade A; Ravi averages 55 and receives grade B under these illustrative thresholds.
Avoid common mistakes
- Specify how missing marks, an empty mark list and invalid scores are handled.
- Grade thresholds are application requirements, not built-in Go rules.
Try it yourself
Add subject names, validate that marks are from 0 to 100, and sort students by average.
Tip: Edit the example above, predict the output, and run the modified code to test your reasoning.
Check your understanding
What you should remember
You have practiced Student Marks Manager in a small, self-contained program. The important habit is to predict what runs, inspect the actual output and distinguish the language rule from the particular example.
Before continuing, make sure you can explain the program to someone who has not seen it, including the line that changes its result.
Reaching the recap and completing the quizzes are separate milestones.