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,23 @@
// 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() {
ops, ok, fail := 2350, 543, 433
fmt.Println(
"total:", ops, "- success:", ok, "/", fail,
)
fmt.Printf(
"total: %d - success: %d / %d\n",
ops, ok, fail,
)
}

View File

@@ -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() {
var brand string
// prints the string in quoted-form like this ""
fmt.Printf("%q\n", brand)
brand = "Google"
fmt.Printf("%q\n", brand)
}

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() {
// without newline
fmt.Println("hihi")
// with newline:
// \n = escape sequence
// \ = escape character
fmt.Println("hi\nhi")
// escape characters:
// \\ = \
// \" = "
fmt.Println("hi\\n\"hi\"")
}

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() {
// I'm using multiple declaration instead of singular
var (
speed int
heat float64
off bool
brand string
)
fmt.Printf("%T\n", speed)
fmt.Printf("%T\n", heat)
fmt.Printf("%T\n", off)
fmt.Printf("%T\n", brand)
}

View File

@@ -0,0 +1,51 @@
// 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 (
planet = "venus"
distance = 261
orbital = 224.701
hasLife = false
)
// swiss army knife %v verb
fmt.Printf("Planet: %v\n", planet)
fmt.Printf("Distance: %v millions kms\n", distance)
fmt.Printf("Orbital Period: %v days\n", orbital)
fmt.Printf("Does %v have life? %v\n", planet, hasLife)
// argument indexing - indexes start from 1
fmt.Printf(
"%v is %v away. Think! %[2]v kms! %[1]v OMG.\n",
planet, distance,
)
// why use other verbs than? because: type-safety
// uncomment to see the warnings:
//
// fmt.Printf("Planet: %d\n", planet)
// fmt.Printf("Distance: %s millions kms\n", distance)
// fmt.Printf("Orbital Period: %t days\n", orbital)
// fmt.Printf("Does %v has life? %f\n", planet, hasLife)
// correct verbs:
// fmt.Printf("Planet: %s\n", planet)
// fmt.Printf("Distance: %d millions kms\n", distance)
// fmt.Printf("Orbital Period: %f days\n", orbital)
// fmt.Printf("Does %s has life? %t\n", planet, hasLife)
// precision
fmt.Printf("Orbital Period: %f days\n", orbital)
fmt.Printf("Orbital Period: %.0f days\n", orbital)
fmt.Printf("Orbital Period: %.1f days\n", orbital)
fmt.Printf("Orbital Period: %.2f days\n", orbital)
}

View File

@@ -0,0 +1,23 @@
// 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
// Print your age using Prinft
//
// EXPECTED OUTPUT
// My age is 30 years old.
//
// NOTE
// You should change 30 to your age, of course.
// ---------------------------------------------------------
func main() {
// ?
}

View File

@@ -0,0 +1,14 @@
// 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() {
fmt.Printf("My age is %d years old.\n", 30)
}

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
// ---------------------------------------------------------
// EXERCISE
// Print your name and lastname using Printf
//
// EXPECTED OUTPUT
// My name is Inanc and my lastname is Gumus.
//
// BONUS
// Store the formatting specifier (first argument of Printf)
// in a variable.
// Then pass it to printf
// ---------------------------------------------------------
func main() {
// BONUS: Use a variable for the format specifier
// fmt.Printf("?", ?, ?)
}

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() {
fmt.Printf("My name is %s and my lastname is %s.\n", "Inanc", "Gumus")
// BONUS
msg := "My name is %s and my lastname is %s.\n"
fmt.Printf(msg, "Inanc", "Gumus")
}

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
// ---------------------------------------------------------
// EXERCISE
// Use printf to print the expected output using a variable.
//
// EXPECTED OUTPUT
// These are false claims.
// ---------------------------------------------------------
func main() {
// UNCOMMENT THE FOLLOWING CODE
// AND DO NOT CHANGE IT AFTERWARDS
// tf := false
// TYPE YOUR CODE HERE
// ?
}

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() {
tf := false
fmt.Printf("These are %t claims.\n", tf)
}

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
// Print the current temperature in your area using Printf
//
// NOTE
// Do not use %v verb
// Output "shouldn't" be like 29.500000
//
// EXPECTED OUTPUT
// Temperature is 29.5 degrees.
// ---------------------------------------------------------
func main() {
// ?
}

View File

@@ -0,0 +1,14 @@
// 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() {
fmt.Printf("Temperature is %.1f degrees.\n", 29.5)
}

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
// Print "hello world" with double-quotes using Printf
// (As you see here)
//
// NOTE
// Output "shouldn't" be just: hello world
//
// EXPECTED OUTPUT
// "hello world"
// ---------------------------------------------------------
func main() {
// ?
}

View File

@@ -0,0 +1,14 @@
// 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() {
fmt.Printf("%q\n", "hello world")
}

View File

@@ -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
// ---------------------------------------------------------
// EXERCISE
// Print the type and value of 3 using fmt.Printf
//
// EXPECTED OUTPUT
// Type of 3 is int
// ---------------------------------------------------------
func main() {
// ?
}

View File

@@ -0,0 +1,14 @@
// 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() {
fmt.Printf("Type of %d is %T\n", 3, 3)
}

View File

@@ -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
// ---------------------------------------------------------
// EXERCISE
// Print the type and value of 3.14 using fmt.Printf
//
// EXPECTED OUTPUT
// Type of 3.14 is float64
// ---------------------------------------------------------
func main() {
// ?
}

View File

@@ -0,0 +1,14 @@
// 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() {
fmt.Printf("Type of %f is %T\n", 3.14, 3.14)
}

View File

@@ -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
// ---------------------------------------------------------
// EXERCISE
// Print the type and value of "hello" using fmt.Printf
//
// EXPECTED OUTPUT
// Type of hello is string
// ---------------------------------------------------------
func main() {
// ?
}

View File

@@ -0,0 +1,14 @@
// 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() {
fmt.Printf("Type of %s is %T\n", "hello", "hello")
}

View File

@@ -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
// ---------------------------------------------------------
// EXERCISE
// Print the type and value of true using fmt.Printf
//
// EXPECTED OUTPUT
// Type of true is bool
// ---------------------------------------------------------
func main() {
// ?
}

View File

@@ -0,0 +1,14 @@
// 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() {
fmt.Printf("Type of %t is %T\n", true, true)
}

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. Get your name and lastname from the command-line
// 2. Print them using Printf
//
// EXAMPLE INPUT
// Inanc Gumus
//
// EXPECTED OUTPUT
// Your name is Inanc and your lastname is Gumus.
// ---------------------------------------------------------
func main() {
// BONUS: Use a variable for the format specifier
}

View File

@@ -0,0 +1,23 @@
// 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"
"os"
)
func main() {
// WARNING: This program will error
// if you don't pass your name and lastname
name, lastname := os.Args[1], os.Args[2]
msg := "Your name is %s and your lastname is %s.\n"
fmt.Printf(msg, name, lastname)
}

Binary file not shown.

View File

@@ -0,0 +1,90 @@
## Which code is correct?
* `fmt.Printf("Hi %s")`
* `fmt.Printf("Hi %s", "how", "are you")`
* `fmt.Printf("Hi %s", "hello")` *CORRECT*
* `fmt.Printf("Hi %s", true)`
## Which code is correct?
* `fmt.Printf("Hi %s %s", "there")`
* `fmt.Printf("Hi %s %s", "5", true)`
* `fmt.Printf("Hi %s %s", "there", ".")` *CORRECT*
* `fmt.Printf("Hi %s %s", "true", false)`
## Which verb is used for an int value?
* %f
* %d *CORRECT*
* %s
* %t
## Which verb is used for a float value?
* %f *CORRECT*
* %d
* %s
* %t
## Which verb is used for a string value?
* %f
* %d
* %s *CORRECT*
* %t
## Which verb is used for a bool value?
* %f
* %d
* %s
* %t *CORRECT*
## Which verb you can use for any type of value?
* %f
* %d
* %v *CORRECT*
* %t
## What does "\n" print?
* \n
* Prints a newline *CORRECT*
* Prints an empty string
## What does "\\n" print?
* \n *CORRECT*
* Prints a newline
* Prints an empty string
## What does "c:\\secret\\directory" print?
* "c:\\secret\\directory"
* c:\\secret\\directory
* c:\secret\directory *CORRECT*
## What does "\"heisenberg\"" print?
* ERROR
* heisenberg
* "heisenberg" *CORRECT*
* 'heisenberg'
## What does `fmt.Printf("%T", 3.14)` print?
* ERROR
* int
* float64 *CORRECT*
* string
* bool
## What does `fmt.Printf("%T", true)` print?
* ERROR
* int
* float64
* string
* bool *CORRECT*
## What does `fmt.Printf("%T", 42)` print?
* ERROR
* int *CORRECT*
* float64
* string
* bool
## What does `fmt.Printf("%T", "hi")` print?
* ERROR
* int
* float64
* string *CORRECT*
* bool