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
intandstring). - Input and output using the
fmtpackage. - Reading user input using the
bufioandospackages. - Converting strings to numbers using the
strconvpackage. - Using conditional statements (
if,else if,else). - Using loops (
for). - Generating random numbers using the
math/randpackage.
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 versionThis 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.
This project is licensed under the MIT License. See the LICENSE file for details. Free to use, modify, and distribute as needed.