Let us write a simple program to accept two numbers and print their sum, product, difference, and quotient. The concepts we have learned so far in our previous posts will be used in this topic.
- Go module system
- Operators in Go Lang
- Variables in Go Lang
- Reading Data from console
- Writing data to the screen
This will solidify your knowledge and help you move forward. This is a practical post, so you can follow along and run the code on your machine.

Create the project folder
mkdir golab_hands_on_simple_application
cd golab_hands_on_simple_application
[commands may vary based on your OS]
Now initialize the Go module system by executing the go mod init command. This is optional for this simple project because we don’t have many dependencies, but it is a good practice to follow for any real-world application.
go mod init github.com/srnyapathi/golab_hands_on_simple_application
The Go module system will initialize the module.
go mod init github.com/srnyapathi/golab_hands_on_simple_application
go: creating new go.mod: module github.com/srnyapathi/golab_hands_on_simple_application
Writing the program
We will read two numbers from the user, so we need to declare two variables. We also need to prompt the user, and for that we use fmt.Print.
var num1, num2 float64
fmt.Print("Enter first number: ")
fmt.Scan(&num1)
fmt.Print("Enter second number: ")
fmt.Scan(&num2)
Logic
You will find variables initialized using the shorthand operator (:=), which handles both variable declaration and assignment.
- Sum +
- Product *
- Difference –
- Quotient /
sum := num1 + num2
product := num1 * num2
difference := num1 - num2
quotient := num1 / num2
Output
We use fmt.Printf to print values along with a formatted output.
%.2f\nis a format stringSum:/Product/Difference/Quotient → literal text that will be printed.%→ starts a placeholder (a “slot” where a value is inserted)..2→ precision: 2 digits after the decimal point.f→ floating-point number (likefloat/double).\n→ newline (moves to the next line after printing).
fmt.Printf("Sum: %.2f\n", sum)
fmt.Printf("Product: %.2f\n", product)
fmt.Printf("Difference: %.2f\n", difference)
fmt.Printf("Quotient: %.2f\n", quotient)
The whole program
package main
import "fmt"
func main() {
var num1, num2 float64
fmt.Print("Enter first number: ")
fmt.Scan(&num1)
fmt.Print("Enter second number: ")
fmt.Scan(&num2)
sum := num1 + num2
product := num1 * num2
difference := num1 - num2
quotient := num1 / num2
fmt.Printf("Sum: %.2f\n", sum)
fmt.Printf("Product: %.2f\n", product)
fmt.Printf("Difference: %.2f\n", difference)
fmt.Printf("Quotient: %.2f\n", quotient)
}
Running the code
go run main.go
The output will look like this:

Here you go! This reinforces the concepts you have learned so far.
Some things to expand on
- Try running this program and supply
0as one of the inputs (especially the second number) and see what happens. Think about why the output looks the way it does.
Repo Link – https://github.com/srnyapathi/golab_package_examples



