Initial commit

This commit is contained in:
Inanc Gumus
2018-10-13 23:30:21 +03:00
commit cde4e6632c
567 changed files with 17896 additions and 0 deletions

View File

@ -0,0 +1,16 @@
// 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 speed int
fmt.Println(speed)
}

View 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
// VARIABLE NAMING RULES
func main() {
// CORRECT DECLARATIONS
var speed int
var SpeeD int
// underscore is allowed but not recommended
var _speed int
// unicode letters are allowed
var 速度 int
// keep the compiler happy
_, _, _, _ = speed, SpeeD, _speed, 速度
}

View 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() {
// fmt.Println(speed)
// var speed int
}

View 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
import "fmt"
func main() {
var nFiles int
var counter int
var nCPU int
fmt.Println(
nFiles,
counter,
nCPU,
)
}

View 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
import "fmt"
func main() {
var heat float64
var ratio float64
var degree float64
fmt.Println(
heat,
ratio,
degree,
)
}

View 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
import "fmt"
func main() {
var off bool
var valid bool
var closed bool
fmt.Println(
off,
valid,
closed,
)
}

View 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
import "fmt"
func main() {
var msg string
var name string
var text string
fmt.Println(
msg,
name,
text,
)
}

View File

@ -0,0 +1,27 @@
// 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"
// EXERCISE: Let's run this to see the zero-values yourself
func main() {
var speed int // numeric type
var heat float64 // numeric type
var off bool
var brand string
fmt.Println(speed)
fmt.Println(heat)
fmt.Println(off)
// I've used printf to print an empty string
// EXERCISE: Use Println to see what happens
fmt.Printf("%q\n", brand)
}

View 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
// there's no warning for package-level vars
var packageLevelVar string
func main() {
// unused variable error
// var speed int
// if you use it, the error will be gone
// fmt.Println(speed)
}

View File

@ -0,0 +1,16 @@
// 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 speed int
// let's assign the variable to the blank-identifier
// so that Go compiler won't get grumpy
_ = speed
}

View 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
import "fmt"
func main() {
var (
speed int
heat float64
off bool
brand string
)
fmt.Println(speed)
fmt.Println(heat)
fmt.Println(off)
fmt.Printf("%q\n", brand)
}

View 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
import "fmt"
func main() {
// this is equal to:
//
// var (
// speed int
// velocity int
// )
//
// or:
//
// var speed int
// var velocity int
//
var speed, velocity int
fmt.Println(speed, velocity)
}

View 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
import "fmt"
func main() {
// names are case-sensitive:
// MyAge, myAge, and MYAGE are different variables
// USE-CASE:
// When to use a parallel declaration?
//
// NOT GOOD:
// var myAge int
// var yourAge int
//
// SO-SO:
// var (
// myAge int
// yourAge int
// )
//
// BETTER:
var myAge, yourAge int
fmt.Println(myAge, yourAge)
var temperature float64
fmt.Println(temperature)
var success bool
fmt.Println(success)
var language string
fmt.Println(language)
}

View 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 ? ?
// ?
}

View 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)
}

View 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 ? ?
// ?
}

View 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)
}

View 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 ? ?
// ?
}

View 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)
}

View 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
}

View 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)
}

View 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
}

View 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
}

View 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....
}

View 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)
}

View 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)
}

View 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)
}

View 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", ?, ?)
}

View 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)
}

View 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() {
}

View 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
}

View 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() {
}

View 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() {
}

View 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 ? ?
}

View 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
}

View File

@ -0,0 +1,22 @@
# QUESTIONS: What's a variable?
* **Where does a variable live?**
* Hard Disk
* Computer Memory - *CORRECT*
* CPU
* **What do you use a variable's name for?**
* To be able to access it later - *CORRECT*
* It's just a label
* I don't need to use it
* **How to change the value of a variable?**
* By using its name - *CORRECT*
* By using its value
* By asking to Go
* **After its declaration can you change the variable's type?**
* Yes : Go is dynamically-typed
* No : Go is statically-typed - *CORRECT*
* Both: Go supports both of them

View File

@ -0,0 +1,21 @@
## Which statement do you need to use for declaring variables?
* name int
* vars string name
* var name integer
* var width int *CORRECT*
## Which sentence below is correct?
* You can use a variable before declaring it
* You have to declare a variable before using it *CORRECT*
## What kind of language is Go?
* Weakly-Typed
* Dynamically-Typed
* Strongly-Typed *CORRECT*
* Freely-Typed
## Which variable name below is correct?
* int
* four *CORRECT*
* 2computers
* one?there

View File

@ -0,0 +1,14 @@
## What happens when you don't use a declared variable in the block scope?
* Nothing, it will work fine
* It will get removed automatically
* The program won't compile *CORRECT*
## What happens when you don't use a declared variable in the package scope?
* Nothing, it will work fine *CORRECT*
* It will get removed automatically
* The program won't compile
## How can you prevent unused variable error?
* You can change the variable's name
* You can use a blank-identifier to discard it *CORRECT*
* You can change the variable's type

View File

@ -0,0 +1,23 @@
## Which type's zero value is 0?
- bool
- pointer
- string
- all numeric types *CORRECT*
## Which type's zero value is false?
- bool *CORRECT*
- pointer
- string
- all numeric types
## Which type's zero value is ""?
- bool
- pointer
- string *CORRECT*
- all numeric types
## Which type's zero value is nil?
- bool
- pointer *CORRECT*
- string
- all numeric types