Loading
0x80Lesson 9 of 9

Practical lab: build an order summary

Combine parsing, validation, and grouping in one realistic workflow.

14 min 4-question quiz 1 code exercise
By the end of this lesson you can
  • Generate a deterministic region summary from mixed-quality rows.

Real internal tools often transform raw rows into grouped reports. This lab combines string parsing, validation, and accumulation. You will read records in the form region,amount, ignore bad rows, and produce a fixed-format summary.

main.go
1package main
2
3import (
4    "fmt"
5    "strings"
6)
7
8func main() {
9    row := "north,14"
10    parts := strings.Split(row, ",")
11    fmt.Println(parts[0])
12}
Output
north

Treat malformed rows and invalid amounts as expected data-quality cases. Keep output deterministic (north then south) so tests and integrations can depend on a stable contract.

Key takeaways

  • Generate a deterministic region summary from mixed-quality rows.

  • Go catches many mistakes while compiling.

  • Use small experiments to understand each new language feature.

Lesson quiz

4 questions · pass with 3 correct · up to 50 XP

Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.

Practice: write Go

Write Go in the editor and run it against sample input with a remote compiler. Your code is sent to Compiler Explorer to compile and run.

Exercise 1

Build a two-region order report

+25 XP

Read an integer count and then count rows formatted as region,amount. Valid regions are north and south. Ignore unknown regions and invalid amounts. Print exactly north=<total>; south=<total>.

  • Valid and invalid rows
  • Only south rows
main.go
Loading editor…

Go is compiled and run by Compiler Explorer (godbolt.org), a free public service. Your source code and test input are sent to that service.

Questions about this lesson

Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.

Loading posts…