Welcome, brave explorer! 🚀
Ever wondered what Go is and how to have fun with it? Let’s learn the basics by creating a simple number guessing game.
Go is a modern language created at Google – it’s fast, friendly, and (almost) never bites. 🐶
In this tutorial, you'll become a Go wizard 🧙♂️ by mastering:
- Basic structure of a Go program (
package main
,import
,func main
). - Importing packages (
fmt
,math/rand
,os
,strconv
,strings
,time
). - Working with variables and data types (especially
int
andstring
). - Input and output using the
fmt
package. - Reading user input using the
bufio
andos
packages. - Converting strings to numbers using the
strconv
package. - Using conditional statements (
if
,else if
,else
). - Using loops (
for
). - Generating random numbers using the
math/rand
package.
For this tutorial, you don't need any prior knowledge of Go. You should have Go installed on your computer. If you don't have it yet, you can download and install it from the official Go website.
After installation, open your terminal and check the version:
go version
This should print the installed Go version.
I recommend using Visual Studio Code and installing the “Go” extension by the Go Team at Google. This will make writing and debugging Go code much easier.
- Open VS Code.
- Click on the square icon on the left sidebar (Extensions).
- In the search bar, type "Go".
- Find the extension named "Go" by "Go Team at Google" and click the "Install" button.
After installing this extension, developing in Go within VS Code will be much more convenient.
Your main file should be named, for example, Guess.go
.
- Make sure you are in the folder with this file.
- Open your terminal and run:
go run Guess.go
- Follow the instructions in the program.
- Every line of code is commented to help you understand what’s happening.
- If you want to try your own extension (for example, a limited number of guesses or hints), try modifying the code after completing this basic version.