0
0
Goprogramming~15 mins

Constants in Go - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Constants in Go
๐Ÿ“– Scenario: You are creating a simple program to calculate the area of a circle. You will use a constant for the value of Pi to keep your code clean and easy to update.
๐ŸŽฏ Goal: Build a Go program that defines a constant for Pi, uses it to calculate the area of a circle with a given radius, and prints the result.
๐Ÿ“‹ What You'll Learn
Create a constant named Pi with the value 3.14
Create a variable named radius with the value 5
Calculate the area of the circle using the formula Pi * radius * radius
Print the area with a descriptive message
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Constants are used in programs to store values that do not change, like mathematical constants, configuration values, or fixed settings.
๐Ÿ’ผ Career
Understanding constants is important for writing clear, maintainable code in any software development job.
Progress0 / 4 steps
1
Create the radius variable
Create a variable called radius and set it to 5.
Go
Need a hint?

Use radius := 5 inside the main function.

2
Define the Pi constant
Define a constant named Pi with the value 3.14 above the main function.
Go
Need a hint?

Write const Pi = 3.14 before the main function.

3
Calculate the area
Create a variable called area and set it to the calculation Pi * radius * radius inside the main function.
Go
Need a hint?

Use area := Pi * float64(radius) * float64(radius) to calculate the area.

4
Print the area
Print the message "Area of the circle:" followed by the value of area using fmt.Println.
Go
Need a hint?

Use fmt.Println("Area of the circle:", area) to print the result.