Initial commit
This commit is contained in:
22
06-variables/02-declarations/exercises/01/main.go
Normal file
22
06-variables/02-declarations/exercises/01/main.go
Normal file
@ -0,0 +1,22 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE
|
||||
// 1- Declare and print a variable with an int type
|
||||
// 2- The declared variable's name should be: height
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// 0
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
// var ? ?
|
||||
// ?
|
||||
}
|
18
06-variables/02-declarations/exercises/01/solution/main.go
Normal file
18
06-variables/02-declarations/exercises/01/solution/main.go
Normal file
@ -0,0 +1,18 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var height int
|
||||
|
||||
fmt.Println(height)
|
||||
}
|
22
06-variables/02-declarations/exercises/02/main.go
Normal file
22
06-variables/02-declarations/exercises/02/main.go
Normal file
@ -0,0 +1,22 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// OPTIONAL EXERCISE
|
||||
// 1- Declare and print a bool variable
|
||||
// 2- The variable's name should be: isOn
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// false
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
// var ? ?
|
||||
// ?
|
||||
}
|
17
06-variables/02-declarations/exercises/02/solution/main.go
Normal file
17
06-variables/02-declarations/exercises/02/solution/main.go
Normal file
@ -0,0 +1,17 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var isOn bool
|
||||
fmt.Println(isOn)
|
||||
}
|
22
06-variables/02-declarations/exercises/03/main.go
Normal file
22
06-variables/02-declarations/exercises/03/main.go
Normal file
@ -0,0 +1,22 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE
|
||||
// 1- Declare and print a variable with a float64 type
|
||||
// 2- The declared variable's name should be: brightness
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// 0
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
// var ? ?
|
||||
// ?
|
||||
}
|
18
06-variables/02-declarations/exercises/03/solution/main.go
Normal file
18
06-variables/02-declarations/exercises/03/solution/main.go
Normal file
@ -0,0 +1,18 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var brightness int
|
||||
|
||||
fmt.Println(brightness)
|
||||
}
|
28
06-variables/02-declarations/exercises/04/main.go
Normal file
28
06-variables/02-declarations/exercises/04/main.go
Normal file
@ -0,0 +1,28 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE
|
||||
// 1- Declare a string variable
|
||||
// 2- Print that variable
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// ""
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
// USE THE BELOW CODE
|
||||
// You'll learn about Printf later
|
||||
|
||||
// var ?
|
||||
// fmt.Printf("s (%T): %q\n", s, s)
|
||||
|
||||
// %T prints the type of the value
|
||||
// %q prints an empty string
|
||||
}
|
15
06-variables/02-declarations/exercises/04/solution/main.go
Normal file
15
06-variables/02-declarations/exercises/04/solution/main.go
Normal file
@ -0,0 +1,15 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
var s string
|
||||
fmt.Printf("s (%T): %q\n", s, s)
|
||||
}
|
33
06-variables/02-declarations/exercises/05/main.go
Normal file
33
06-variables/02-declarations/exercises/05/main.go
Normal file
@ -0,0 +1,33 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE
|
||||
// 1- Declare the variables below:
|
||||
// 3speed
|
||||
// !speed
|
||||
// spe?ed
|
||||
// var
|
||||
// func
|
||||
// package
|
||||
//
|
||||
// 2- Observe the error messages
|
||||
//
|
||||
// NOTE
|
||||
// The types of the variables are not important.
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
// var ? int
|
||||
// var ? int
|
||||
// var ? int
|
||||
// var ? int
|
||||
// var ? int
|
||||
// var ? int
|
||||
}
|
17
06-variables/02-declarations/exercises/05/solution/main.go
Normal file
17
06-variables/02-declarations/exercises/05/solution/main.go
Normal file
@ -0,0 +1,17 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
// var 3speed int
|
||||
// var !speed int
|
||||
// var spe?ed int
|
||||
// var var int
|
||||
// var func int
|
||||
// var package int
|
||||
}
|
41
06-variables/02-declarations/exercises/06/main.go
Normal file
41
06-variables/02-declarations/exercises/06/main.go
Normal file
@ -0,0 +1,41 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE
|
||||
// 1- Declare a few variables using the following types
|
||||
// int
|
||||
// int8
|
||||
// int16
|
||||
// int32
|
||||
// int64
|
||||
// float32
|
||||
// float64
|
||||
// complex64
|
||||
// complex128
|
||||
// bool
|
||||
// string
|
||||
// rune
|
||||
// byte
|
||||
//
|
||||
// 2- Observe their output
|
||||
// 3- After you've done, check out the solution
|
||||
// and read the comments there
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// 0 0 0 0 0 0 0 false 0 0
|
||||
// ""
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
// var i int
|
||||
// var i8 int8
|
||||
|
||||
// CONTINUE FROM HERE....
|
||||
}
|
40
06-variables/02-declarations/exercises/06/solution/main.go
Normal file
40
06-variables/02-declarations/exercises/06/solution/main.go
Normal file
@ -0,0 +1,40 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
// integer types
|
||||
var i int
|
||||
var i8 int8
|
||||
var i16 int16
|
||||
var i32 int32
|
||||
var i64 int64
|
||||
|
||||
// float types
|
||||
var f32 float32
|
||||
var f64 float64
|
||||
|
||||
// bool type
|
||||
var b bool
|
||||
|
||||
// string types
|
||||
var s string
|
||||
var r rune // also a numeric type
|
||||
var by byte // also a numeric type
|
||||
|
||||
fmt.Println(
|
||||
i, i8, i16, i32, i64,
|
||||
f32, f64,
|
||||
b, r, by,
|
||||
)
|
||||
|
||||
// You could do it with Println as well
|
||||
fmt.Printf("%q\n", s)
|
||||
}
|
32
06-variables/02-declarations/exercises/07/main.go
Normal file
32
06-variables/02-declarations/exercises/07/main.go
Normal file
@ -0,0 +1,32 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE
|
||||
// 1. Declare two variables using
|
||||
// multiple variable declaration statement
|
||||
//
|
||||
// 2. The first variable's name should be active
|
||||
// 3. The second variable's name should be delta
|
||||
//
|
||||
// 4. Print them all
|
||||
//
|
||||
// HINT
|
||||
// You should declare a bool and an int variable
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// false 0
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
// var (
|
||||
// ?
|
||||
// )
|
||||
// fmt.Println(active, delta)
|
||||
}
|
18
06-variables/02-declarations/exercises/07/solution/main.go
Normal file
18
06-variables/02-declarations/exercises/07/solution/main.go
Normal file
@ -0,0 +1,18 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
var (
|
||||
active bool
|
||||
delta int
|
||||
)
|
||||
fmt.Println(active, delta)
|
||||
}
|
34
06-variables/02-declarations/exercises/08/main.go
Normal file
34
06-variables/02-declarations/exercises/08/main.go
Normal file
@ -0,0 +1,34 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE
|
||||
// 1. Declare and initialize two string variables
|
||||
// using multiple variable declaration
|
||||
//
|
||||
// 2. Use the type once while declaring the variables
|
||||
//
|
||||
// 3. The first variable's name should be firstName
|
||||
// 4. The second variable's name should be lastName
|
||||
//
|
||||
// 5. Print them all
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// "" ""
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
// ADD YOUR DECLARATION HERE
|
||||
//
|
||||
|
||||
// REPLACE THE QUESTION-MARKS BELOW
|
||||
// WITH THE NAME OF YOUR VARIABLES
|
||||
|
||||
// fmt.Printf("%q %q\n", ?, ?)
|
||||
}
|
15
06-variables/02-declarations/exercises/08/solution/main.go
Normal file
15
06-variables/02-declarations/exercises/08/solution/main.go
Normal file
@ -0,0 +1,15 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
var firstName, lastName string = "", ""
|
||||
fmt.Printf("%q %q\n", firstName, lastName)
|
||||
}
|
21
06-variables/02-declarations/exercises/09/main.go
Normal file
21
06-variables/02-declarations/exercises/09/main.go
Normal file
@ -0,0 +1,21 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE
|
||||
// 1- Declare a variable
|
||||
// 2- Variable's name should be: isLiquid
|
||||
// 3- Discard it using a blank-identifier
|
||||
//
|
||||
// NOTE
|
||||
// Do not print the variable
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
}
|
13
06-variables/02-declarations/exercises/09/solution/main.go
Normal file
13
06-variables/02-declarations/exercises/09/solution/main.go
Normal file
@ -0,0 +1,13 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
var isLiquid bool
|
||||
_ = isLiquid
|
||||
}
|
19
06-variables/02-declarations/exercises/10/main.go
Normal file
19
06-variables/02-declarations/exercises/10/main.go
Normal file
@ -0,0 +1,19 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE
|
||||
// 1- Declare a variable in the package-scope
|
||||
//
|
||||
// 2- Observe whether something happens when you don't
|
||||
// use it
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
}
|
13
06-variables/02-declarations/exercises/10/solution/main.go
Normal file
13
06-variables/02-declarations/exercises/10/solution/main.go
Normal file
@ -0,0 +1,13 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
var isLiquid bool
|
||||
|
||||
func main() {
|
||||
}
|
24
06-variables/02-declarations/exercises/11/main.go
Normal file
24
06-variables/02-declarations/exercises/11/main.go
Normal file
@ -0,0 +1,24 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE
|
||||
// 1- Print a variable
|
||||
// 2- Then declare it
|
||||
// (This means: Try to print it before its declaration)
|
||||
// 3- Observe the error
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
// First print it:
|
||||
// fmt.Println(?)
|
||||
|
||||
// Then declare it:
|
||||
// var ? ?
|
||||
}
|
15
06-variables/02-declarations/exercises/11/solution/main.go
Normal file
15
06-variables/02-declarations/exercises/11/solution/main.go
Normal file
@ -0,0 +1,15 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
// UNCOMMENT THE CODE BELOW TO SEE THE ERROR
|
||||
|
||||
// fmt.Println(age)
|
||||
// var age int
|
||||
}
|
Reference in New Issue
Block a user