Go Playground

A starter program to experiment with. Edit it here, press Copy, paste it into a file called main.go, and run it with go run main.go. Lesson 2 shows how to install Go.

Try it yourself · main.go
Edit the code, copy it into main.go in a new folder and run it with go run main.go (Go 1.27 or later). How to install Go
Output
Backpack     1 x  39.90 =   39.90
Notebook     4 x   3.50 =   14.00
Pen         10 x   1.20 =   12.00
Total: 65.90

Ideas to try

  • Apply a 10% discount when the total is over 50 (lesson 14).
  • Read the items from a CSV file with bufio.Scanner and strings.Split (lesson 57).
  • Group items into "cheap" and "expensive" with a map of slices (lesson 28).
  • Add a NewItem constructor that returns an error for negative prices (lessons 36 and 44).
  • Give Item a String method so fmt.Println(it) prints a tidy line (lesson 42).
  • Serve the basket as JSON from an HTTP endpoint (lessons 59 and 61).

Running Go without installing anything

The Go Playground at go.dev/play compiles and runs programs in your browser and lets you share them by link. It's great for quick experiments; for files, input and servers you'll want a local installation.