71 lines
1.1 KiB
Go
71 lines
1.1 KiB
Go
/*
|
|
Coding Exercise #1
|
|
|
|
Using the const keyword declare and initialize the following constants:
|
|
|
|
1. daysWeek with value 7
|
|
|
|
2. lightSpeed with value 299792458
|
|
|
|
3. pi with value 3.14159
|
|
|
|
Run the program without errors.
|
|
|
|
package main
|
|
|
|
func main() {
|
|
const daysWeek = 7
|
|
const lightSpeed = 299792458
|
|
const pi = 3.14159
|
|
|
|
}
|
|
*/
|
|
|
|
/*
|
|
Coding Exercise #2
|
|
|
|
Change the code from the previous exercise and declare all 3 constants as grouped constants.
|
|
|
|
Make them untyped.
|
|
|
|
func main() {
|
|
const (
|
|
daysWeek = 7
|
|
lightSpeed = 299792458
|
|
pi = 3.14159
|
|
)
|
|
|
|
}
|
|
*/
|
|
|
|
/*
|
|
Coding Exercise #3
|
|
|
|
Calculate how many seconds are in a year.
|
|
|
|
STEPS:
|
|
|
|
1. Declare secPerDay constant and initialize it to the number of seconds in a day
|
|
|
|
2. Declare daysYear constant and initialize it to 365
|
|
|
|
3. Use fmt.Printf() to print out the total number of seconds in a year.
|
|
|
|
EXPECTED OUTPUT:
|
|
|
|
There are 31536000 seconds in a year.
|
|
*/
|
|
package main
|
|
|
|
import "fmt"
|
|
|
|
func main() {
|
|
const (
|
|
daysYear = 365
|
|
hoursDay = 24
|
|
secondsHour = 3600
|
|
)
|
|
var result = daysYear * hoursDay * secondsHour
|
|
fmt.Printf("Seconds in a Year %d\n", result)
|
|
}
|