Initial commit
This commit is contained in:
31
06-variables/03-short-declaration/exercises/01/main.go
Normal file
31
06-variables/03-short-declaration/exercises/01/main.go
Normal file
@ -0,0 +1,31 @@
|
||||
// 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
|
||||
// Declare and then print four variables
|
||||
// using the short declaration statement
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// i: 314 f: 3.14 s: Hello b: true
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
// ADD YOUR DECLARATIONS HERE
|
||||
//
|
||||
|
||||
// THEN UNCOMMENT THE CODE BELOW
|
||||
|
||||
// fmt.Println(
|
||||
// "i:", i,
|
||||
// "f:", f,
|
||||
// "s:", s,
|
||||
// "b:", b,
|
||||
// )
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
// 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() {
|
||||
i := 314
|
||||
f := 3.14
|
||||
s := "Hello"
|
||||
b := true
|
||||
|
||||
fmt.Println(
|
||||
"i:", i,
|
||||
"f:", f,
|
||||
"s:", s,
|
||||
"b:", b,
|
||||
)
|
||||
}
|
25
06-variables/03-short-declaration/exercises/02/main.go
Normal file
25
06-variables/03-short-declaration/exercises/02/main.go
Normal file
@ -0,0 +1,25 @@
|
||||
// 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
|
||||
// Declare two variables using multiple short declaration
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// 14 true
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
// ADD YOUR DECLARATIONS HERE
|
||||
//
|
||||
|
||||
// THEN UNCOMMENT THE CODE BELOW
|
||||
|
||||
// fmt.Println(a, b)
|
||||
}
|
@ -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() {
|
||||
a, b := 14, true
|
||||
|
||||
fmt.Println(a, b)
|
||||
}
|
28
06-variables/03-short-declaration/exercises/03/main.go
Normal file
28
06-variables/03-short-declaration/exercises/03/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 two variables using short declaration
|
||||
//
|
||||
// 2- `a` variable's value should be 42
|
||||
// 3- `c` variable's value should be "good"
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// 42 good
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
// ADD YOUR DECLARATIONS HERE
|
||||
//
|
||||
|
||||
// THEN UNCOMMENT THE CODE BELOW
|
||||
|
||||
// fmt.Println(a, c)
|
||||
}
|
@ -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() {
|
||||
a, c := 42, "good"
|
||||
|
||||
fmt.Println(a, c)
|
||||
}
|
25
06-variables/03-short-declaration/exercises/04/main.go
Normal file
25
06-variables/03-short-declaration/exercises/04/main.go
Normal file
@ -0,0 +1,25 @@
|
||||
// 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- Short declare a variable named `sum`
|
||||
// 2- Initialize it with an expression by adding 27 and 3.5
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// 30.5
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
// ADD YOUR DECLARATION HERE
|
||||
//
|
||||
|
||||
// THEN UNCOMMENT THE CODE BELOW
|
||||
// fmt.Println(sum)
|
||||
}
|
@ -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() {
|
||||
sum := 27 + 3.5
|
||||
|
||||
fmt.Println(sum)
|
||||
}
|
34
06-variables/03-short-declaration/exercises/05/main.go
Normal file
34
06-variables/03-short-declaration/exercises/05/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- Short declare two bool variables
|
||||
// (use multiple short declaration syntax)
|
||||
//
|
||||
// 2- Initialize both variables to true
|
||||
//
|
||||
// 3- Change your declaration and
|
||||
// discard the 2nd variable's value
|
||||
// using the blank-identifier
|
||||
//
|
||||
// 4- Print only the 1st variable
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// true
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
// ADD YOUR DECLARATIONS HERE
|
||||
//
|
||||
|
||||
// THEN UNCOMMENT THE CODE BELOW
|
||||
|
||||
// fmt.Println(on)
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
// 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() {
|
||||
// You can discard values in a short declaration
|
||||
|
||||
on, _ := true, true
|
||||
|
||||
fmt.Println(on)
|
||||
}
|
33
06-variables/03-short-declaration/exercises/06/main.go
Normal file
33
06-variables/03-short-declaration/exercises/06/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- Short declare two int variables: age and yourAge
|
||||
// (use multiple short declaration syntax)
|
||||
//
|
||||
// 2- Short declare a new float variable: ratio
|
||||
// And, change the 'age' variable to 42
|
||||
//
|
||||
// (! You should use redeclaration)
|
||||
//
|
||||
// 4- Print all the variables
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// 42, 20, 3.14
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
// ADD YOUR DECLARATIONS HERE
|
||||
//
|
||||
|
||||
// THEN UNCOMMENT THE CODE BELOW
|
||||
|
||||
// fmt.Println(age, yourAge, ratio)
|
||||
}
|
@ -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
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
age, yourAge := 10, 20
|
||||
age, ratio := 42, 3.14
|
||||
|
||||
fmt.Println(age, yourAge, ratio)
|
||||
}
|
Reference in New Issue
Block a user