O'Reilly logo

Get Programming with Go by Nathan Youngman and Roger Peppé

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required