Lesson 2. A glorified calculator

After reading lesson 2, you’ll be able to

  • Teach a computer to do your math
  • Declare variables and constants
  • See how declaration and assignment differ
  • Use the standard library to generate pseudorandom numbers

Computer programs are capable of a great many things. In this lesson you’ll write programs to solve mathematical problems.

Consider this

Why write a program when you could just use a calculator?

Well, have you memorized the speed of light or how long it takes Mars to orbit the sun? Code can be saved and read later, serving as both a calculator and a reference. A program is an executable document that can be shared and modified.

2.1. Performing calculations

There are days when we ...

Get Get Programming with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.