Primitive Types
Reading material
A Tour of Go: Basic types.
First exercise
// primitive_types1
// Make me compile!
// I AM NOT DONE
package main
import "fmt"
func main() {
storeIsOpen := true
if storeIsOpen {
fmt.Println("The store is open, let's buy some clothes!")
}
storeIsOpen
if !storeIsOpen {
fmt.Println("Oh no, let's buy some clothes online!")
}
}
Second exercise
// primitive_types2
// Make me compile!
// I AM NOT DONE
package main
import "fmt"
func main() {
fmt.Printf("Hello, %s\n", who) // '%s' is used to format strings
}
Third exercise
// primitive_types3
// Make me compile!
// I AM NOT DONE
package main
import "fmt"
func main() {
fmt.Printf("Hello, I am %s and live in %s\n", who, country)
}
Fourth exercise
// primitive_types4
// Make me compile!
// I AM NOT DONE
package main
import "fmt"
func main() {
var b1 byte = 110
fmt.Println("byte value for b1:", b1)
var b2 byte = ''
fmt.Println("representation for b2:", b2)
}
Fifth exercise
// primitive_types5
// Make me compile!
// I AM NOT DONE
package main
import "fmt"
func main() {
var n1 integer = 101
if n1 > 100 {
fmt.Println("It is a big number")
} else {
fmt.Println("Not a big number at all")
}
var n2 float = 0.99
fmt.Println(n2)
}
If something is wrong in this page, edit this page on GitHub