From dc4aaea4fa5a18e8b24a5204ac38d24886ede29e Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Fri, 19 Oct 2018 20:31:10 +0300 Subject: [PATCH] fix: massive questions markdown fix --- .../02-code-your-first-program-questions.md | 96 +++++++++++---- .../03-run-your-first-program-questions.md | 28 +++-- .../questions/01-packages-A.md | 12 +- 03-packages-and-scopes/questions/02-scopes.md | 32 +++-- .../questions/01-statements.md | 52 ++++++-- .../questions/03-comments.md | 24 +++- .../printer-exercise/questions.md | 76 +++++++++--- .../02-declarations/questions/01-what.md | 8 +- .../questions/01-arithmetic-operators.md | 48 ++++++-- .../01-numbers/questions/02-precedence.md | 4 +- .../questions/03-assignment-operations.md | 84 +++++++++---- .../02-strings/questions/questions.md | 111 +++++++++++++----- .../01-questions-predeclared-types.md | 68 ++++++++--- .../questions/02-questions-defined-types.md | 59 +++++++--- 10-constants/questions/questions.md | 47 ++++++-- 11-if/questions/3-if.md | 8 +- .../02-code-your-first-program-questions.md | 96 +++++++++++---- .../03-run-your-first-program-questions.md | 28 +++-- 18 files changed, 657 insertions(+), 224 deletions(-) diff --git a/02-write-your-first-program/questions/02-code-your-first-program-questions.md b/02-write-your-first-program/questions/02-code-your-first-program-questions.md index 0179102..3067ef3 100644 --- a/02-write-your-first-program/questions/02-code-your-first-program-questions.md +++ b/02-write-your-first-program/questions/02-code-your-first-program-questions.md @@ -10,10 +10,18 @@ func main() { 3. fmt.Println 4. import -> 1. This keyword is used to declare a new function. -> 2. That's right! package keyword allows you to define which package a Go file belongs to. -> 3. This is not a keyword. It's the Println function of the fmt package. -> 4. This keyword is used to import a package. +> **1:** This keyword is used to declare a new function. +> +> +> **2:** That's right! package keyword allows you to define which package a Go file belongs to. +> +> +> **3:** This is not a keyword. It's the Println function of the fmt package. +> +> +> **4:** This keyword is used to import a package. +> +> ## Which keyword is used to declare a new function? @@ -29,16 +37,24 @@ func main() { 3. It allows Go to import a package called function. 4. It prints a message to the console. -> 2. Go looks for package main and func main to do that. A function doesn't do that on its own. -> 3. `import` keyword does that. -> 4. For example: `fmt.Println` does that. +> **2:** Go looks for package main and func main to do that. A function doesn't do that on its own. +> +> +> **3:** `import` keyword does that. +> +> +> **4:** For example: `fmt.Println` does that. +> +> ## Do you have to call the main function yourself? 1. Yes, so that, I can execute my program. 2. No, Go calls the main function automatically. *CORRECT* -> 1. No, you don't need to call the main function. Go automatically executes it. +> **1:** No, you don't need to call the main function. Go automatically executes it. +> +> ## Do you have to call the other functions yourself? @@ -46,11 +62,17 @@ func main() { 2. Yes, so that, Go can execute my program. 3. No, Go calls the functions automatically. -> 1. That's right. You need to call a function yourself. Go won't execute it automatically. Go only calls the main function automatically (and some other functions which you didn't learn about yet). +> **1:** That's right. You need to call a function yourself. Go won't execute it automatically. Go only calls the main function automatically (and some other functions which you didn't learn about yet). +> +> -> 2. That's only the job of the `func main`. There's only one `func main`. +> **2:** That's only the job of the `func main`. There's only one `func main`. +> +> -> 3. Go doesn't call any function automatically except the main func (and some other functions which you didn't learn about yet). So, except the main func, you need to call the functions yourself. +> **3:** Go doesn't call any function automatically except the main func (and some other functions which you didn't learn about yet). So, except the main func, you need to call the functions yourself. +> +> ## What does `package main` do? @@ -76,9 +98,15 @@ func main() { 2. Go starts executing your program by using the code inside func main *CORRECT* 3. It prints a message to the console -> 1. main function doesn't contain a package. -> 2. That's right. Go automatically calls the main function to execute your program. -> 3. It doesn't print anything at least directly. +> **1:** main function doesn't contain a package. +> +> +> **2:** That's right. Go automatically calls the main function to execute your program. +> +> +> **3:** It doesn't print anything at least directly. +> +> ## What does `import "fmt"` do? @@ -94,9 +122,15 @@ func main() { 2. It defines a new package called "fmt" 3. It imports the `fmt` package; so you can use its functionalities *CORRECT* -> 1. `fmt.Println` prints a message not the `import "fmt"`. -> 2. `package` keyword does that, not the `import` keyword. -> 3. Yes. For example, after you import the fmt package you can call its Println function to print a message to the console. +> **1:** `fmt.Println` prints a message not the `import "fmt"`. +> +> +> **2:** `package` keyword does that, not the `import` keyword. +> +> +> **3:** Yes. For example, after you import the fmt package you can call its Println function to print a message to the console. +> +> ## What this program does? @@ -110,11 +144,17 @@ func main() { 2. It's a correct program but it doesn't print anything *CORRECT* 3. It's an incorrect program -> 1. It doesn't print a message. To do that you can use fmt.Println function. +> **1:** It doesn't print a message. To do that you can use fmt.Println function. +> +> -> 2. Yes, it's a correct program but since it doesn't contain fmt.Println it doesn't print anything. +> **2:** Yes, it's a correct program but since it doesn't contain fmt.Println it doesn't print anything. +> +> -> 3. It's a correct program. It uses the package keyword and it has a main function. So, this is a valid and an executable Go program. +> **3:** It's a correct program. It uses the package keyword and it has a main function. So, this is a valid and an executable Go program. +> +> ## What does this program print? @@ -129,9 +169,13 @@ func main() { * It doesn't print anything * This program is incorrect *CORRECT* -> 1. It doesn't pass the message to Println wrapped between double-quotes. It should be like: fmt.Println("Hi! I want to be a Gopher") +> **1:** It doesn't pass the message to Println wrapped between double-quotes. It should be like: fmt.Println("Hi! I want to be a Gopher") +> +> -> 3. It doesn't import "fmt" package. Also see #1. +> **3:** It doesn't import "fmt" package. Also see #1. +> +> ## What does this program print? @@ -147,5 +191,9 @@ func main() { * fmt * This program is incorrect; it imports the wrong package or there isn't a function called `Println` -> 2. import "fmt" imports the `fmt` package; so you can use its functionalities. -> 3. Actually, this program is correct. \ No newline at end of file +> **2:** import "fmt" imports the `fmt` package; so you can use its functionalities. +> +> +> **3:** Actually, this program is correct. +> +> \ No newline at end of file diff --git a/02-write-your-first-program/questions/03-run-your-first-program-questions.md b/02-write-your-first-program/questions/03-run-your-first-program-questions.md index f0959ad..b9f0b19 100644 --- a/02-write-your-first-program/questions/03-run-your-first-program-questions.md +++ b/02-write-your-first-program/questions/03-run-your-first-program-questions.md @@ -2,8 +2,12 @@ 1. `go run` just compiles a program; whereas `go build` both compiles and runs it. 2. `go run` both compiles and runs a program; whereas `go build` just compiles it. *CORRECT* -> 1. It's opposite actually. -> 2. `go run` compiles your program and puts it in a temporary directory. Then it runs the compiled program in there. +> **1:** It's opposite actually. +> +> +> **2:** `go run` compiles your program and puts it in a temporary directory. Then it runs the compiled program in there. +> +> ## Which directory `go build` puts the compiled code into? @@ -12,8 +16,12 @@ 3. $GOPATH/pkg directory 4. Into a temporary directory. -> 2. There only lives Go source-code files -> 3. Go only puts your code there when you call `go install`. +> **2:** There only lives Go source-code files +> +> +> **3:** Go only puts your code there when you call `go install`. +> +> ## Which directory `go run` puts the compiled code into? @@ -38,6 +46,12 @@ 2. While it runs (after compile-time). *CORRECT* 3. While it runs (inside the compile-time). -> 1. In the compilation step your program cannot print a message. In that stage, it's literally dead. -> 2. That's right. That's the only time which your program can interact with a computer and instruct it to print a message to the console. -> 3. Running can only happen after the compile-time \ No newline at end of file +> **1:** In the compilation step your program cannot print a message. In that stage, it's literally dead. +> +> +> **2:** That's right. That's the only time which your program can interact with a computer and instruct it to print a message to the console. +> +> +> **3:** Running can only happen after the compile-time +> +> \ No newline at end of file diff --git a/03-packages-and-scopes/questions/01-packages-A.md b/03-packages-and-scopes/questions/01-packages-A.md index eaf0e99..79d3410 100644 --- a/03-packages-and-scopes/questions/01-packages-A.md +++ b/03-packages-and-scopes/questions/01-packages-A.md @@ -8,8 +8,12 @@ 2. It's used for letting Go know that the file belong to a package *CORRECT* 3. It's used for declaring a new function -> 1. `import` statement does that. -> 3. `func` statement does that. +> **1:** `import` statement does that. +> +> +> **3:** `func` statement does that. +> +> ## Where you should put the `package clause` in a Go source-code file? @@ -41,4 +45,6 @@ 3. go run go 4. go run *.go *CORRECT* -> 4. You can also call it like (assuming there are file1.go file2.go and file3.go in the same directory): go run file1.go file2.go file3.go \ No newline at end of file +> **4:** You can also call it like (assuming there are file1.go file2.go and file3.go in the same directory): go run file1.go file2.go file3.go +> +> \ No newline at end of file diff --git a/03-packages-and-scopes/questions/02-scopes.md b/03-packages-and-scopes/questions/02-scopes.md index a29d787..fb10a99 100644 --- a/03-packages-and-scopes/questions/02-scopes.md +++ b/03-packages-and-scopes/questions/02-scopes.md @@ -22,7 +22,9 @@ func block() { 3. enabled **CORRECT** 4. counter -> 3. That's right. `enabled` is out of any functions, so it's a package scoped name. `block()` function is also package scoped; it's out of any function too. +> **3:** That's right. `enabled` is out of any functions, so it's a package scoped name. `block()` function is also package scoped; it's out of any function too. +> +> ## Which name below is file scoped? @@ -32,7 +34,9 @@ func block() { 4. block() 5. counter -> 2. That's right. Imported package names are file scoped. And they can only be used within the same file. +> **2:** That's right. Imported package names are file scoped. And they can only be used within the same file. +> +> ## Which name below is in the scope of the block() func? @@ -42,7 +46,9 @@ func block() { 4. block() 5. counter **CORRECT** -> 5. That's right. `counter` is declared within the `block()` func, so it's in the scope of the block func. Out of the `block()` func, other code can't see it. +> **5:** That's right. `counter` is declared within the `block()` func, so it's in the scope of the block func. Out of the `block()` func, other code can't see it. +> +> ## Can `block()` see `enabled` name? @@ -50,7 +56,9 @@ func block() { 2. No: It's in the file scope 3. No: It's in the block scope of block() -> 1. All code inside the same package can see all the other package level declared names. +> **1:** All code inside the same package can see all the other package level declared names. +> +> ## Can other files in `awesome` package see `counter` name? @@ -59,7 +67,9 @@ func block() { 3. No: It's in the file scope 4. No: It's in the block scope of block() **CORRECT** -> 4. That's right. None of the other code can see the names inside the `block()` function. Only the code inside the `block()` function can see them (Only to some extend. For example: Inside the block, the code can only see the variables declared before it.) +> **4:** That's right. None of the other code can see the names inside the `block()` function. Only the code inside the `block()` function can see them (Only to some extend. For example: Inside the block, the code can only see the variables declared before it.) +> +> ## Can other files in `awesome` package see `fmt` name? @@ -68,7 +78,9 @@ func block() { 3. No: It's in the file scope **CORRECT** 4. No: It's in the block scope of block() -> 3. Only the same file can see the imported packages, not the other files whether they're in the same package or not. +> **3:** Only the same file can see the imported packages, not the other files whether they're in the same package or not. +> +> ## What happens if you declare the same name in the same scope like this: @@ -90,7 +102,9 @@ func block() { 2. I can't do that. It's already been declared at the package scope. *CORRECT* 3. I can't do that. It's already been declared at the file scope. -> 2. That's right. You can't declare the same name in the same scope. If you could do so, then how would you access it again? Or to which one? +> **2:** That's right. You can't declare the same name in the same scope. If you could do so, then how would you access it again? Or to which one? +> +> ## What happens if you declare the same name in another scope like this: @@ -114,4 +128,6 @@ func block() { 2. I can't do that. It's already been declared at the package scope. 3. I can't do that. It's already been declared at the file scope. -> 1. Actually, you can declare the same name in the inner scopes like this. `block()`'s scope is inside its package. This means that it can access to its package's scope (but not vice versa). So, `block()`'s scope is under its package's scope. This means that you can declare the same name again. It will override the parent scope's name. They both can be exist together. Check out the example in the course repository to find out. \ No newline at end of file +> **1:** Actually, you can declare the same name in the inner scopes like this. `block()`'s scope is inside its package. This means that it can access to its package's scope (but not vice versa). So, `block()`'s scope is under its package's scope. This means that you can declare the same name again. It will override the parent scope's name. They both can be exist together. Check out the example in the course repository to find out. +> +> \ No newline at end of file diff --git a/04-statements-expressions-comments/questions/01-statements.md b/04-statements-expressions-comments/questions/01-statements.md index 0c42e73..2950b19 100644 --- a/04-statements-expressions-comments/questions/01-statements.md +++ b/04-statements-expressions-comments/questions/01-statements.md @@ -3,8 +3,12 @@ 2. A statement produces a value 3. A statement can't change the execution flow -> 2. A statement can't produce a value. However, it can indirectly help producing a value. -> 3. It surely can. +> **2:** A statement can't produce a value. However, it can indirectly help producing a value. +> +> +> **3:** It surely can. +> +> ## What's the direction of execution in a Go code? @@ -13,7 +17,9 @@ 3. From right to left 4. From bottom to top -> 2. That's right. Go executes the code from top-to-bottom, one statement at a time. +> **2:** That's right. Go executes the code from top-to-bottom, one statement at a time. +> +> ## Which one is the correct description for an expression? @@ -21,8 +27,12 @@ 2. An expression produces a value *CORRECT* 3. An expression can change the execution flow -> 1. It can't. Only a statement can do that. -> 3. It can't. Only a statement can do that. +> **1:** It can't. Only a statement can do that. +> +> +> **3:** It can't. Only a statement can do that. +> +> ## Which one is the correct description for an operator? @@ -30,8 +40,12 @@ 2. An operator can change the execution flow 3. An operator can combine expressions *CORRECT* -> 1. It can't. Only a statement can do that. -> 2. It can't. Only a statement can do that. +> **1:** It can't. Only a statement can do that. +> +> +> **2:** It can't. Only a statement can do that. +> +> ## Why the following code doesn't work? @@ -66,9 +80,15 @@ func main() { 2. It doesn't work: Statements should be on their own on a single line of code 3. It works: Go adds semicolons behind the scenes for every statement already *CORRECT* -> 1. It works but that's not the reason. And, expressions can't be typed like that. -> 2. Are you sure? -> 3. That's right. Whether there's a semicolon or not; Go adds them automatically. Those statements are still assumed as they're on a different code line of their own. +> **1:** It works but that's not the reason. And, expressions can't be typed like that. +> +> +> **2:** Are you sure? +> +> +> **3:** That's right. Whether there's a semicolon or not; Go adds them automatically. Those statements are still assumed as they're on a different code line of their own. +> +> ## Why this code works? @@ -88,6 +108,12 @@ func main() { 2. Statements can be used with operators 3. Expressions can return multiple values -> 1. That's right. + operator combines `runtime.NumCPU()` and `10` expressions. -> 2. No, they can't be. For example, you can't do this: `import "fmt" + 3`. Some statement can allow expressions. However, this doesn't mean that they can be combined using expressions. -> 3. That's right however it's irrelevant to why this code works. \ No newline at end of file +> **1:** That's right. + operator combines `runtime.NumCPU()` and `10` expressions. +> +> +> **2:** No, they can't be. For example, you can't do this: `import "fmt" + 3`. Some statement can allow expressions. However, this doesn't mean that they can be combined using expressions. +> +> +> **3:** That's right however it's irrelevant to why this code works. +> +> \ No newline at end of file diff --git a/04-statements-expressions-comments/questions/03-comments.md b/04-statements-expressions-comments/questions/03-comments.md index aa67d06..9bab74c 100644 --- a/04-statements-expressions-comments/questions/03-comments.md +++ b/04-statements-expressions-comments/questions/03-comments.md @@ -39,17 +39,27 @@ func main() { } ``` -> 1. `/` is not a comment. It should be `//`. -> 2. Multiline comments can be put almost anywhere. However, when a comment starts with `/*`, it also needs to end with `*/`. Here, Go doesn't interpret `/* ... */`, it just skips it. And, when Go sees `//` as the first two characters in a code, it skips the whole line. -> 3. `//` prevents Go to interpret the rest of the code line. That's why this code doesn't work. Go can't interpret this part because of the comment: `"this will print Hi!")` +> **1:** `/` is not a comment. It should be `//`. +> +> +> **2:** Multiline comments can be put almost anywhere. However, when a comment starts with `/*`, it also needs to end with `*/`. Here, Go doesn't interpret `/* ... */`, it just skips it. And, when Go sees `//` as the first two characters in a code, it skips the whole line. +> +> +> **3:** `//` prevents Go to interpret the rest of the code line. That's why this code doesn't work. Go can't interpret this part because of the comment: `"this will print Hi!")` +> +> ## How should you name your code so that Go can generate documentation from your code automatically? 1. By commenting the each line of the code; then it will generate the documentation from whatever it sees 2. By starting the comments using the name of the declared names *CORRECT* 3. By using multi-line comments -> 1. This won't help. Sorry. -> 3. It doesn't matter whether you type your comments using single-line comments or multi-line comments. +> **1:** This won't help. Sorry. +> +> +> **3:** It doesn't matter whether you type your comments using single-line comments or multi-line comments. +> +> ## Which tool do you need to use from the command-line to print the documentation? @@ -65,4 +75,6 @@ func main() { 3. `go` tool is the real tool behind `go doc` 4. `go` tool is the real tool behind `godoc` -> 2. That's right. go doc tool uses godoc tool behind the scenes. go doc is just a simplified version of the godoc tool. \ No newline at end of file +> **2:** That's right. go doc tool uses godoc tool behind the scenes. go doc is just a simplified version of the godoc tool. +> +> \ No newline at end of file diff --git a/05-write-your-first-library-package/printer-exercise/questions.md b/05-write-your-first-library-package/printer-exercise/questions.md index 92135dc..1c81201 100644 --- a/05-write-your-first-library-package/printer-exercise/questions.md +++ b/05-write-your-first-library-package/printer-exercise/questions.md @@ -6,9 +6,15 @@ 3. You can compile a library package. *CORRECT* 4. You have to compile a library package. -> 1. You can't, but you can import it from other packages. -> 2. In a library package, you don't have to include a main function. Because, it isn't an executable package. Only in executable packages you need a main func. -> 4. You don't have to compile it. When you import it, it will automatically be built by the other program or library when it gets compiled or ran. +> **1:** You can't, but you can import it from other packages. +> +> +> **2:** In a library package, you don't have to include a main function. Because, it isn't an executable package. Only in executable packages you need a main func. +> +> +> **4:** You don't have to compile it. When you import it, it will automatically be built by the other program or library when it gets compiled or ran. +> +> ## What do you need to export a name? @@ -17,10 +23,18 @@ 3. You need to put it inside a function scope 4. You need to create a new file for that name -> 1. When you do so, it will be exported, that's true, but don't do that; so I assume that this answer is not correct :) -> 2. That's right. Then the other packages can access it. -> 3. It should be in a package scope, not function scope. -> 4. You don't have to do that. +> **1:** When you do so, it will be exported, that's true, but don't do that; so I assume that this answer is not correct :) +> +> +> **2:** That's right. Then the other packages can access it. +> +> +> **3:** It should be in a package scope, not function scope. +> +> +> **4:** You don't have to do that. +> +> ## How can you use a function from your library from an executable program? @@ -29,10 +43,18 @@ 3. You can access your library package as if it's in your executable program 4. You can import it just by using its name -> 1. You can't export packages. All packages are already exported. Unless you put them in a directory called: "internal". But, that's an advanced topic for now. -> 2. That's right. -> 3. You can't access to a package from another package without importing it. -> 4. No, you can't. You need to import it using its full directory path after GOPATH. BTW, in the near future this may change with the Go modules support. +> **1:** You can't export packages. All packages are already exported. Unless you put them in a directory called: "internal". But, that's an advanced topic for now. +> +> +> **2:** That's right. +> +> +> **3:** You can't access to a package from another package without importing it. +> +> +> **4:** No, you can't. You need to import it using its full directory path after GOPATH. BTW, in the near future this may change with the Go modules support. +> +> ## In the following program, which names are exported? @@ -55,10 +77,18 @@ func Fireball() { 3. Fireball *CORRECT* 4. Println -> 1. That's just an imported package name. -> 2. It starts with a lowercase letter; so, it's not exported. -> 3. That's right. It starts with a capital letter. -> 4. This isn't your function. It's already been exported in the fmt package. But, it isn't exported here. +> **1:** That's just an imported package name. +> +> +> **2:** It starts with a lowercase letter; so, it's not exported. +> +> +> **3:** That's right. It starts with a capital letter. +> +> +> **4:** This isn't your function. It's already been exported in the fmt package. But, it isn't exported here. +> +> ## In the following program, which names are exported? @@ -84,7 +114,15 @@ func Fireball() { 3. Fireball, greenTrees and Two 4. Fireball, greenTrees, one and Two -> 1. doMagic starts with a lowercase letter; so, it's not exported. -> 2. That's right. Fireball and Two, they both start with a capital letter. -> 3. greenTrees starts with a lowercase letter; so, it's not exported. -> 4. one and greenTrees do not start with capital letters; so, they're not exported. \ No newline at end of file +> **1:** doMagic starts with a lowercase letter; so, it's not exported. +> +> +> **2:** That's right. Fireball and Two, they both start with a capital letter. +> +> +> **3:** greenTrees starts with a lowercase letter; so, it's not exported. +> +> +> **4:** one and greenTrees do not start with capital letters; so, they're not exported. +> +> \ No newline at end of file diff --git a/06-variables/02-declarations/questions/01-what.md b/06-variables/02-declarations/questions/01-what.md index 7fab952..702801a 100644 --- a/06-variables/02-declarations/questions/01-what.md +++ b/06-variables/02-declarations/questions/01-what.md @@ -1,21 +1,21 @@ # QUESTIONS: What's a variable? -* **Where does a variable live?** +## Where does a variable live? * Hard Disk * Computer Memory - *CORRECT* * CPU -* **What do you use a variable's name for?** +## 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?** +## 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?** +## 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 diff --git a/08-numbers-and-strings/01-numbers/questions/01-arithmetic-operators.md b/08-numbers-and-strings/01-numbers/questions/01-arithmetic-operators.md index 0db3511..ad261e8 100644 --- a/08-numbers-and-strings/01-numbers/questions/01-arithmetic-operators.md +++ b/08-numbers-and-strings/01-numbers/questions/01-arithmetic-operators.md @@ -10,8 +10,12 @@ 3. 57 *CORRECT* 4. "Try Me!" -> 4. Nice Try. But, that's not right. Sorry. -> 3. That's right. The remainder operator only works on integer values. +> **4:** Nice Try. But, that's not right. Sorry. +> +> +> **3:** That's right. The remainder operator only works on integer values. +> +> ## What's the result of this expression? @@ -43,7 +47,9 @@ var degree float64 = 10 / 4 3. 2 *CORRECT* 4. 0 -> 3. That's right. An integer value cannot contain fractional parts. +> **3:** That's right. An integer value cannot contain fractional parts. +> +> ## What's the result of this expression? @@ -55,7 +61,9 @@ var degree float64 = 3. / 2 3. 1 4. 0 -> 1. That's right. `3.` makes the whole expression a float value. +> **1:** That's right. `3.` makes the whole expression a float value. +> +> ## What's the type of the `x` variable? @@ -67,10 +75,18 @@ x := 5 * 2. 3. bool 4. string -> 1. Look closely to 2 there. -> 2. Why? Because, `2.` there makes the expressions a float value. Cool. -> 3. Oh, come on! Life is not always true and false. -> 4. I can't see any double-quotes or back-quotes, can you? +> **1:** Look closely to 2 there. +> +> +> **2:** Why? Because, `2.` there makes the expressions a float value. Cool. +> +> +> **3:** Oh, come on! Life is not always true and false. +> +> +> **4:** I can't see any double-quotes or back-quotes, can you? +> +> ## What's the type of the `x` variable? @@ -82,10 +98,18 @@ x := 5 * -(2) 3. bool 4. string -> 1. Why? Because, there only integer numbers. -> 2. I can't see any fractional parts there, can you? -> 3. Oh, come on! Life is not always true and false. -> 4. I can't see any double-quotes or back-quotes, can you? +> **1:** Why? Because, there only integer numbers. +> +> +> **2:** I can't see any fractional parts there, can you? +> +> +> **3:** Oh, come on! Life is not always true and false. +> +> +> **4:** I can't see any double-quotes or back-quotes, can you? +> +> ## Which kind of values can result in inaccurate calculations? diff --git a/08-numbers-and-strings/01-numbers/questions/02-precedence.md b/08-numbers-and-strings/01-numbers/questions/02-precedence.md index e3e4897..39778f1 100644 --- a/08-numbers-and-strings/01-numbers/questions/02-precedence.md +++ b/08-numbers-and-strings/01-numbers/questions/02-precedence.md @@ -41,4 +41,6 @@ 4. -12 5. -12.0 *CORRECT* -> 4. You're close but remember! The result of an expression with floats and integers is always a float. \ No newline at end of file +> **4:** You're close but remember! The result of an expression with floats and integers is always a float. +> +> \ No newline at end of file diff --git a/08-numbers-and-strings/01-numbers/questions/03-assignment-operations.md b/08-numbers-and-strings/01-numbers/questions/03-assignment-operations.md index 775d9e3..cc5be46 100644 --- a/08-numbers-and-strings/01-numbers/questions/03-assignment-operations.md +++ b/08-numbers-and-strings/01-numbers/questions/03-assignment-operations.md @@ -7,9 +7,15 @@ var n float64 3. `n = n + 1` *CORRECT* 4. `++n` -> 1. This just assigns 1 to n. -> 2. IncDec statement can't be used as an operator. -> 4. Go doesn't support prefix incdec notation. +> **1:** This just assigns 1 to n. +> +> +> **2:** IncDec statement can't be used as an operator. +> +> +> **4:** Go doesn't support prefix incdec notation. +> +> ## Which expression decreases `n` by 1? @@ -21,9 +27,15 @@ var n int 3. `n = n - 1` *CORRECT* 4. `--n` -> 1. This just assigns -1 to n. -> 2. IncDec statement can't be used as an operator. -> 4. Go doesn't support prefix incdec notation. +> **1:** This just assigns -1 to n. +> +> +> **2:** IncDec statement can't be used as an operator. +> +> +> **4:** Go doesn't support prefix incdec notation. +> +> ## Which code below equals to `n = n + 1`? @@ -32,9 +44,15 @@ var n int 3. `++n` 4. `n = n ++ 1` -> 2. IncDec statement can't be used as an operator. -> 3. Go doesn't support prefix incdec notation. -> 4. What's that? ++? +> **2:** IncDec statement can't be used as an operator. +> +> +> **3:** Go doesn't support prefix incdec notation. +> +> +> **4:** What's that? ++? +> +> ## Which code below equals to `n = n + 1`? @@ -43,9 +61,15 @@ var n int 3. `++n` 4. `n = n ++ 1` -> 1. IncDec statement can't be used as an operator. -> 3. Go doesn't support prefix incdec notation. -> 4. What's that? ++? +> **1:** IncDec statement can't be used as an operator. +> +> +> **3:** Go doesn't support prefix incdec notation. +> +> +> **4:** What's that? ++? +> +> ## Which code below equals to `n -= 1`? @@ -54,9 +78,15 @@ var n int 3. `n--` *CORRECT* 4. `--n` -> 1. IncDec statement can't be used as an operator. -> 2. IncDec statement can't be used as an operator. And also, you can't use it with `1--`. The value should be addressable. You're going to learn what that means soon. -> 4. Go doesn't support prefix incdec notation. +> **1:** IncDec statement can't be used as an operator. +> +> +> **2:** IncDec statement can't be used as an operator. And also, you can't use it with `1--`. The value should be addressable. You're going to learn what that means soon. +> +> +> **4:** Go doesn't support prefix incdec notation. +> +> ## Which code below divides the `length` by 10? @@ -64,9 +94,15 @@ var n int 2. `length /= 10` *CORRECT* 3. `length //= 10` -> 1. What's that? `//`? -> 2. That's right. This equals to: `length = length / 10` -> 3. What's that? `//=`? +> **1:** What's that? `//`? +> +> +> **2:** That's right. This equals to: `length = length / 10` +> +> +> **3:** What's that? `//=`? +> +> ## Which code below equals to `x = x % 2`? @@ -74,8 +110,12 @@ var n int 2. `x =% x` 3. `x %= x` *CORRECT* -> 1. This is a division. You need to use the remainder operator. -> 2. Close... But, the `%` operator is on the wrong side of the assignment. +> **1:** This is a division. You need to use the remainder operator. +> +> +> **2:** Close... But, the `%` operator is on the wrong side of the assignment. +> +> ## Which function below converts a string value into a float value? @@ -95,4 +135,6 @@ func ParseFloat(s string, bitSize int) (float64, error) 3. `strconv.ParseFloat("10", "64")` 4. `strconv.ParseFloat(10, 64)` -> 1. There are no 128-bit floating point values in Go (Actually there are, but they only belong to the compile-time). \ No newline at end of file +> **1:** There are no 128-bit floating point values in Go (Actually there are, but they only belong to the compile-time). +> +> \ No newline at end of file diff --git a/08-numbers-and-strings/02-strings/questions/questions.md b/08-numbers-and-strings/02-strings/questions/questions.md index 39e0604..90835ed 100644 --- a/08-numbers-and-strings/02-strings/questions/questions.md +++ b/08-numbers-and-strings/02-strings/questions/questions.md @@ -8,8 +8,12 @@ 3. "Hello" `"World"` 4. "\"Hello\" `\"World\"`" -> 1. Go doesn't interpret the escape sequences in raw string literals. -> 2. That's right. Go interprets `\"` as `"` but it doesn't do so for ` \"World\"`. +> **1:** Go doesn't interpret the escape sequences in raw string literals. +> +> +> **2:** That's right. Go interprets `\"` as `"` but it doesn't do so for ` \"World\"`. +> +> ## What's the best way to represent the following text in the code? @@ -57,8 +61,11 @@ ` ``` -> 2-3. You can't write a string literal like that. It can't be multiple-lines. -> 4. You don't need to use escape sequences inside raw string literals. +> **2-3:** You can't write a string literal like that. It can't be multiple-lines. +> +> **4:** You don't need to use escape sequences inside raw string literals. +> +> ## What's the result of the following expression? @@ -71,7 +78,9 @@ len("lovely") 3. 6 *CORRECT* 4. 0 -> 2. Remember! "a" is 1 char. `a` is also 1 char. +> **2:** Remember! "a" is 1 char. `a` is also 1 char. +> +> ## What's the result of the following expression? @@ -84,10 +93,18 @@ len("very") + len(`\"cool\"`) 3. 16 4. 10 -> 1. There are also double-quotes, count them as well. -> 2. That's right. Go doesn't interpreted \" in raw string literals. -> 3. Remember! "very" is 4 characters. `very` is also 4 characters. -> 4. Remember! Go doesn't interpreted \" in raw string literals. +> **1:** There are also double-quotes, count them as well. +> +> +> **2:** That's right. Go doesn't interpreted \" in raw string literals. +> +> +> **3:** Remember! "very" is 4 characters. `very` is also 4 characters. +> +> +> **4:** Remember! Go doesn't interpreted \" in raw string literals. +> +> ## What's the result of the following expression? @@ -100,9 +117,15 @@ len("very") + len("\"cool\"") 3. 16 4. 10 *CORRECT* -> 1. There are also double-quotes, count them as well. -> 2. Remember! Go interprets escape sequences in string literals. -> 4. That's right. Go does interpret \" in a string literal. So, "\"" means ", which is 1 character. +> **1:** There are also double-quotes, count them as well. +> +> +> **2:** Remember! Go interprets escape sequences in string literals. +> +> +> **4:** That's right. Go does interpret \" in a string literal. So, "\"" means ", which is 1 character. +> +> ## What's the result of the following expression? @@ -119,9 +142,15 @@ len("péripatéticien") 3. 18 4. 20 -> 1. Remember! é is 2 bytes long. -> 2. An english letter is 1 byte long. However, é is 2 bytes long. So, that makes up 16 bytes. Cool. -> 3. You didn't count the double-quotes, did you? +> **1:** Remember! é is 2 bytes long. +> +> +> **2:** An english letter is 1 byte long. However, é is 2 bytes long. So, that makes up 16 bytes. Cool. +> +> +> **3:** You didn't count the double-quotes, did you? +> +> ## How can you find the correct length of the characters in this string literal? @@ -134,9 +163,15 @@ len("péripatéticien") 3. `utf8.RuneCountInString("péripatéticien")` *CORRECT* 4. `unicode/utf8.RuneCountInString("péripatéticien")` -> 1. Where are the double-quotes? -> 2. This only finds the bytes in a string value. -> 4. You're close. But, the package's name is utf8 not unicode/utf8. +> **1:** Where are the double-quotes? +> +> +> **2:** This only finds the bytes in a string value. +> +> +> **4:** You're close. But, the package's name is utf8 not unicode/utf8. +> +> ## What's the result of the following expression? @@ -149,8 +184,12 @@ utf8.RuneCountInString("péripatéticien") 3. 18 4. 20 -> 1. This is its byte count. `RuneCountInString` counts the runes (codepoints) not the bytes. -> 2. That's right. `RuneCountInString` returns the number of runes (codepoints) in a string value. +> **1:** This is its byte count. `RuneCountInString` counts the runes (codepoints) not the bytes. +> +> +> **2:** That's right. `RuneCountInString` returns the number of runes (codepoints) in a string value. +> +> ## Which package contains string manipulation functions? @@ -172,10 +211,18 @@ strings.Repeat("*x", 3) + "*" 3. `*x3` 4. `*x*x*x*` *CORRECT* -> 1. You're close but you missed the concatenation at the end. -> 2. Look closely. -> 3. Wow! You should really watch the lectures again. Sorry. -> 4. That's right. Repeat function repeats the given string. And, the concatenation operator combines the strings. +> **1:** You're close but you missed the concatenation at the end. +> +> +> **2:** Look closely. +> +> +> **3:** Wow! You should really watch the lectures again. Sorry. +> +> +> **4:** That's right. Repeat function repeats the given string. And, the concatenation operator combines the strings. +> +> ## What's the result of this expression? @@ -188,7 +235,15 @@ strings.ToUpper("bye bye ") + "see you!" 3. `bye bye + see you!` 4. `BYE BYE see you!` *CORRECT* -> 1. You missed the ToUpper? -> 2. You're close but look closely. ToUpper only changes the first part of the string there. -> 3. Not even close. Sorry. -> 4. Perfect! Good catch! ToUpper only changes the first part of the string there. \ No newline at end of file +> **1:** You missed the ToUpper? +> +> +> **2:** You're close but look closely. ToUpper only changes the first part of the string there. +> +> +> **3:** Not even close. Sorry. +> +> +> **4:** Perfect! Good catch! ToUpper only changes the first part of the string there. +> +> \ No newline at end of file diff --git a/09-go-type-system/questions/01-questions-predeclared-types.md b/09-go-type-system/questions/01-questions-predeclared-types.md index f765a09..0935258 100644 --- a/09-go-type-system/questions/01-questions-predeclared-types.md +++ b/09-go-type-system/questions/01-questions-predeclared-types.md @@ -23,7 +23,9 @@ 3. 256 *CORRECT* 4. 65536 -> 3. 2^8 is 256, so you can represent 256 different states. +> **3:** 2^8 is 256, so you can represent 256 different states. +> +> ## How many bits 2 bytes contains? @@ -45,10 +47,18 @@ fmt.Printf("%08b = %d", 2) > EXPLANATION = From right to left, each bit goes from 2^0 to 2^(n - 1). -> 1. EXPLANATION. Here: 1 is the first digit from the right. So, it is 2^(1 - 1) = 2^0 = 1. -> 2. EXPLANATION. Here: 1 is the second digit from the right. So, it is 2^(2 - 1) = 2^1 = 2. -> 3. EXPLANATION. Here: 1 is the third digit from the right. So, it is 2^(3 - 1) = 2^2 = 4. -> 4. EXPLANATION. Here: 1 is the fourth digit from the right. So, it is 2^(4 - 1) = 2^3 = 8. +> **1:** EXPLANATION. Here: 1 is the first digit from the right. So, it is 2^(1 - 1) = 2^0 = 1. +> +> +> **2:** EXPLANATION. Here: 1 is the second digit from the right. So, it is 2^(2 - 1) = 2^1 = 2. +> +> +> **3:** EXPLANATION. Here: 1 is the third digit from the right. So, it is 2^(3 - 1) = 2^2 = 4. +> +> +> **4:** EXPLANATION. Here: 1 is the fourth digit from the right. So, it is 2^(4 - 1) = 2^3 = 8. +> +> ## How many bytes of memory does an int64 value use? @@ -57,7 +67,9 @@ fmt.Printf("%08b = %d", 2) 3. 32 4. 64 -> 2. 1 byte is 8 bits and int64 is 64 bits. So, 64/8=8 bytes. +> **2:** 1 byte is 8 bits and int64 is 64 bits. So, 64/8=8 bytes. +> +> ## How many bytes are needed to store a value of uint32 type? @@ -66,7 +78,9 @@ fmt.Printf("%08b = %d", 2) 3. 32 4. 64 -> 2. 1 byte is 8 bits and uint32 is 32 bits. So, 32/8=4 bytes. +> **2:** 1 byte is 8 bits and uint32 is 32 bits. So, 32/8=4 bytes. +> +> ## What's the size of int data type? @@ -74,7 +88,9 @@ fmt.Printf("%08b = %d", 2) 2. 32 bits 3. 64 bits -> 1. That's right. Go can change its size at the compile-time depending on which target machine you're compiling your program into. +> **1:** That's right. Go can change its size at the compile-time depending on which target machine you're compiling your program into. +> +> ## English letters can be represented by the numbers within the range of: 0-255. For example, 'A' can be 65. Or, 'B' can be 66. So, what's the best data type for storing an English letter? @@ -84,10 +100,18 @@ fmt.Printf("%08b = %d", 2) 3. int64 4. float64 -> 1. That's right. A byte can represent 0-255 different values. So, it's a great fit for representing English letters, and numbers. -> 2. In practice, you can do it with a rune value. However, rune is 32-bits long and it can store almost every letter in existince. I'm asking for the optimal data type. Try again. -> 3. That would be too large for only 255 different numbers. -> 4. Float is not the best data type for numbers without fractional parts. +> **1:** That's right. A byte can represent 0-255 different values. So, it's a great fit for representing English letters, and numbers. +> +> +> **2:** In practice, you can do it with a rune value. However, rune is 32-bits long and it can store almost every letter in existince. I'm asking for the optimal data type. Try again. +> +> +> **3:** That would be too large for only 255 different numbers. +> +> +> **4:** Float is not the best data type for numbers without fractional parts. +> +> @@ -101,9 +125,15 @@ fmt.Print(letter + 5) 3. 5 4. 260 -> 2. Unsigned integers wrap around after their maximum capacity. Uint8's max is 255, so, if 255 + 1 is 0, then 255 + 5 is 4. -> 3. You're very close. -> 4. Uint8's max capacity is 255. It can't be 260. +> **2:** Unsigned integers wrap around after their maximum capacity. Uint8's max is 255, so, if 255 + 1 is 0, then 255 + 5 is 4. +> +> +> **3:** You're very close. +> +> +> **4:** Uint8's max capacity is 255. It can't be 260. +> +> ## What does the following code print? @@ -115,5 +145,9 @@ fmt.Print(num - 3) 2. 125 *CORRECT* 3. -125 -> 1. int8's min capacity is -128. It can't be -131. -> 2. Signed integers wrap around after their minimum capacity. int8's min is -128, so, if -128 - 1 is 127, then -128 - 3 is 125. \ No newline at end of file +> **1:** int8's min capacity is -128. It can't be -131. +> +> +> **2:** Signed integers wrap around after their minimum capacity. int8's min is -128, so, if -128 - 1 is 127, then -128 - 3 is 125. +> +> \ No newline at end of file diff --git a/09-go-type-system/questions/02-questions-defined-types.md b/09-go-type-system/questions/02-questions-defined-types.md index 655abc5..76abdd3 100644 --- a/09-go-type-system/questions/02-questions-defined-types.md +++ b/09-go-type-system/questions/02-questions-defined-types.md @@ -4,7 +4,8 @@ 3. For readability and conveying meaning 4. All of the options above *CORRECT* -> 1-3. Yes, that's only one of the reasons. +> **1-3:** Yes, that's only one of the reasons. +> ## Let's suppose that you've declared the following defined type. Which property below that the new type doesn't get from its underlying type? @@ -19,8 +20,11 @@ type Millennium time.Duration 3. Size 4. Range of values -> 1. That's right. A defined type doesn't get its source type's methods. -> 2-4. Actually the defined type gets it from its underlying type. +> **1:** That's right. A defined type doesn't get its source type's methods. +> +> +> **2-4:** Actually the defined type gets it from its underlying type. +> ## How to define a new type using float32? @@ -29,9 +33,14 @@ type Millennium time.Duration 3. `type radius float32` *CORRECT* 4. `type radius = float32` -> 1-2. This is not a correct syntax. -> 3. `radius` is a new type, defined using `float32`. -> 4. This declares `radius` as an alias to `float32`. So, they become the same types. +> **1-2:** This is not a correct syntax. +> +> **3:** `radius` is a new type, defined using `float32`. +> +> +> **4:** This declares `radius` as an alias to `float32`. So, they become the same types. +> +> ## How to fix the following code? @@ -50,8 +59,11 @@ fmt.Print(village + city) 3. `village(int) + city` 4. `village + Distance(city)` *CORRECT* -> 1-3. There's a type mismatch in this code. But, this won't fix it. -> 4. That's right. Now, the `city`'s type is Distance in the expression. +> **1-3:** There's a type mismatch in this code. But, this won't fix it. +> +> **4:** That's right. Now, the `city`'s type is Distance in the expression. +> +> ## For the following program which types you might want to declare? @@ -71,9 +83,14 @@ func main() { 3. Temperature using int64 4. Temperature using uint32 -> 1. But a degree value has a floating part. So, using an integer may not the best way. -> 2. float64 can represent a degree value. -> 3-4. But a degree value has a floating part. So, using an integer may not the best way. Also, there are two different temperature units here: Celsius and Fahrenheit. Isn't it better to create two distinct types? +> **1:** But a degree value has a floating part. So, using an integer may not the best way. +> +> +> **2:** float64 can represent a degree value. +> +> +> **3-4:** But a degree value has a floating part. So, using an integer may not the best way. Also, there are two different temperature units here: Celsius and Fahrenheit. Isn't it better to create two distinct types? +> ## What's the underlying type of the Millennium type? @@ -89,9 +106,15 @@ type ( 3. `Century` 4. Another type -> 1. That's right. Go's type system is flat. So, the defined type's underlying type is a type with a real structure. int64 is not just a name, it has its own structure, it's a predeclared type. -> 2. Duration is just a new type name. It doesn't its own structure. -> 3. Century is just a new type name. It doesn't its own structure. +> **1:** That's right. Go's type system is flat. So, the defined type's underlying type is a type with a real structure. int64 is not just a name, it has its own structure, it's a predeclared type. +> +> +> **2:** Duration is just a new type name. It doesn't its own structure. +> +> +> **3:** Century is just a new type name. It doesn't its own structure. +> +> ## Which types do not need to be converted between each other? @@ -102,7 +125,9 @@ type ( 3. rune and uint8 4. byte and uint32 -> 1. byte data type is an alias to uint8 data type. So, they don't need conversion between each other. They're the same types. +> **1:** byte data type is an alias to uint8 data type. So, they don't need conversion between each other. They're the same types. +> +> ## Which types do not need to be converted between each other? @@ -113,4 +138,6 @@ type ( 3. rune and int32 *CORRECT* 4. byte and int8 -> 3. rune data type is an alias to int32 data type. So, they don't need conversion between each other. They're the same types. \ No newline at end of file +> **3:** rune data type is an alias to int32 data type. So, they don't need conversion between each other. They're the same types. +> +> \ No newline at end of file diff --git a/10-constants/questions/questions.md b/10-constants/questions/questions.md index 4fb6efb..7b682b6 100644 --- a/10-constants/questions/questions.md +++ b/10-constants/questions/questions.md @@ -16,7 +16,9 @@ 2. `const version int := 3` 2. `const version int = 3` *CORRECT* -> 1. "C"onst should be just "c"onst. +> **1:** "C"onst should be just "c"onst. +> +> ## Which code below is correct? @@ -24,9 +26,15 @@ 2. `const message = "pick me!"; const length = len(message)` *CORRECT* 3. `const length = utf8.RuneCountInString("pick me")` -> 1. `s` not a constant. -> 2. `len` function can be used as an initial value to a constant, when the argument to `len` is also a constant. -> 3. You cannot call functions while initializing a constant. +> **1:** `s` not a constant. +> +> +> **2:** `len` function can be used as an initial value to a constant, when the argument to `len` is also a constant. +> +> +> **3:** You cannot call functions while initializing a constant. +> +> ## Which explanation below is correct for the following code? @@ -38,8 +46,12 @@ porsche := speed * 3 2. speed's type is int and porsche's type is also int 3. speed and porsche are typeless -> 2. speed has no type. -> 3. A variable cannot be typeless. +> **2:** speed has no type. +> +> +> **3:** A variable cannot be typeless. +> +> ## How to fix the following code? @@ -51,8 +63,11 @@ spell = "Abracadabra" 2. `spell := "Abracadabra"` 3. `var spell = "Abracadabra"` -> 1. A constant always have to be initialized to a value. And, sometimes the type declaration is not necessary. -> 2-3. That's a variable not a constant. +> **1:** A constant always have to be initialized to a value. And, sometimes the type declaration is not necessary. +> +> +> **2-3:** That's a variable not a constant. +> ## How to fix the following code? @@ -83,9 +98,15 @@ x := 5 fmt.Print(int64(total) * x) ``` -> 1. Now, the total constant is typeless, so it can be used with the x variable. -> 2. There's still a type mismatch. x is int not int64. -> 3. total is already int64. No need to convert it again. +> **1:** Now, the total constant is typeless, so it can be used with the x variable. +> +> +> **2:** There's still a type mismatch. x is int not int64. +> +> +> **3:** total is already int64. No need to convert it again. +> +> ## What are the values of the following constants? @@ -101,4 +122,6 @@ const ( 3. Yes=7 No=12 Both=17 4. Yes=2 No=7 Both=12 *CORRECT* -> 3. iota starts at 0, not 1. \ No newline at end of file +> **3:** iota starts at 0, not 1. +> +> \ No newline at end of file diff --git a/11-if/questions/3-if.md b/11-if/questions/3-if.md index 5b124ba..ef7b7ca 100644 --- a/11-if/questions/3-if.md +++ b/11-if/questions/3-if.md @@ -3,5 +3,9 @@ 2. Changing the left-to-right execution of a program 3. Controlling which statements are executed *CORRECT* -> 1. You can't change that. -> 2. You can't change that. +> **1:** You can't change that. +> +> +> **2:** You can't change that. +> +> diff --git a/first/first/questions/02-code-your-first-program-questions.md b/first/first/questions/02-code-your-first-program-questions.md index 0179102..3067ef3 100644 --- a/first/first/questions/02-code-your-first-program-questions.md +++ b/first/first/questions/02-code-your-first-program-questions.md @@ -10,10 +10,18 @@ func main() { 3. fmt.Println 4. import -> 1. This keyword is used to declare a new function. -> 2. That's right! package keyword allows you to define which package a Go file belongs to. -> 3. This is not a keyword. It's the Println function of the fmt package. -> 4. This keyword is used to import a package. +> **1:** This keyword is used to declare a new function. +> +> +> **2:** That's right! package keyword allows you to define which package a Go file belongs to. +> +> +> **3:** This is not a keyword. It's the Println function of the fmt package. +> +> +> **4:** This keyword is used to import a package. +> +> ## Which keyword is used to declare a new function? @@ -29,16 +37,24 @@ func main() { 3. It allows Go to import a package called function. 4. It prints a message to the console. -> 2. Go looks for package main and func main to do that. A function doesn't do that on its own. -> 3. `import` keyword does that. -> 4. For example: `fmt.Println` does that. +> **2:** Go looks for package main and func main to do that. A function doesn't do that on its own. +> +> +> **3:** `import` keyword does that. +> +> +> **4:** For example: `fmt.Println` does that. +> +> ## Do you have to call the main function yourself? 1. Yes, so that, I can execute my program. 2. No, Go calls the main function automatically. *CORRECT* -> 1. No, you don't need to call the main function. Go automatically executes it. +> **1:** No, you don't need to call the main function. Go automatically executes it. +> +> ## Do you have to call the other functions yourself? @@ -46,11 +62,17 @@ func main() { 2. Yes, so that, Go can execute my program. 3. No, Go calls the functions automatically. -> 1. That's right. You need to call a function yourself. Go won't execute it automatically. Go only calls the main function automatically (and some other functions which you didn't learn about yet). +> **1:** That's right. You need to call a function yourself. Go won't execute it automatically. Go only calls the main function automatically (and some other functions which you didn't learn about yet). +> +> -> 2. That's only the job of the `func main`. There's only one `func main`. +> **2:** That's only the job of the `func main`. There's only one `func main`. +> +> -> 3. Go doesn't call any function automatically except the main func (and some other functions which you didn't learn about yet). So, except the main func, you need to call the functions yourself. +> **3:** Go doesn't call any function automatically except the main func (and some other functions which you didn't learn about yet). So, except the main func, you need to call the functions yourself. +> +> ## What does `package main` do? @@ -76,9 +98,15 @@ func main() { 2. Go starts executing your program by using the code inside func main *CORRECT* 3. It prints a message to the console -> 1. main function doesn't contain a package. -> 2. That's right. Go automatically calls the main function to execute your program. -> 3. It doesn't print anything at least directly. +> **1:** main function doesn't contain a package. +> +> +> **2:** That's right. Go automatically calls the main function to execute your program. +> +> +> **3:** It doesn't print anything at least directly. +> +> ## What does `import "fmt"` do? @@ -94,9 +122,15 @@ func main() { 2. It defines a new package called "fmt" 3. It imports the `fmt` package; so you can use its functionalities *CORRECT* -> 1. `fmt.Println` prints a message not the `import "fmt"`. -> 2. `package` keyword does that, not the `import` keyword. -> 3. Yes. For example, after you import the fmt package you can call its Println function to print a message to the console. +> **1:** `fmt.Println` prints a message not the `import "fmt"`. +> +> +> **2:** `package` keyword does that, not the `import` keyword. +> +> +> **3:** Yes. For example, after you import the fmt package you can call its Println function to print a message to the console. +> +> ## What this program does? @@ -110,11 +144,17 @@ func main() { 2. It's a correct program but it doesn't print anything *CORRECT* 3. It's an incorrect program -> 1. It doesn't print a message. To do that you can use fmt.Println function. +> **1:** It doesn't print a message. To do that you can use fmt.Println function. +> +> -> 2. Yes, it's a correct program but since it doesn't contain fmt.Println it doesn't print anything. +> **2:** Yes, it's a correct program but since it doesn't contain fmt.Println it doesn't print anything. +> +> -> 3. It's a correct program. It uses the package keyword and it has a main function. So, this is a valid and an executable Go program. +> **3:** It's a correct program. It uses the package keyword and it has a main function. So, this is a valid and an executable Go program. +> +> ## What does this program print? @@ -129,9 +169,13 @@ func main() { * It doesn't print anything * This program is incorrect *CORRECT* -> 1. It doesn't pass the message to Println wrapped between double-quotes. It should be like: fmt.Println("Hi! I want to be a Gopher") +> **1:** It doesn't pass the message to Println wrapped between double-quotes. It should be like: fmt.Println("Hi! I want to be a Gopher") +> +> -> 3. It doesn't import "fmt" package. Also see #1. +> **3:** It doesn't import "fmt" package. Also see #1. +> +> ## What does this program print? @@ -147,5 +191,9 @@ func main() { * fmt * This program is incorrect; it imports the wrong package or there isn't a function called `Println` -> 2. import "fmt" imports the `fmt` package; so you can use its functionalities. -> 3. Actually, this program is correct. \ No newline at end of file +> **2:** import "fmt" imports the `fmt` package; so you can use its functionalities. +> +> +> **3:** Actually, this program is correct. +> +> \ No newline at end of file diff --git a/first/first/questions/03-run-your-first-program-questions.md b/first/first/questions/03-run-your-first-program-questions.md index f0959ad..b9f0b19 100644 --- a/first/first/questions/03-run-your-first-program-questions.md +++ b/first/first/questions/03-run-your-first-program-questions.md @@ -2,8 +2,12 @@ 1. `go run` just compiles a program; whereas `go build` both compiles and runs it. 2. `go run` both compiles and runs a program; whereas `go build` just compiles it. *CORRECT* -> 1. It's opposite actually. -> 2. `go run` compiles your program and puts it in a temporary directory. Then it runs the compiled program in there. +> **1:** It's opposite actually. +> +> +> **2:** `go run` compiles your program and puts it in a temporary directory. Then it runs the compiled program in there. +> +> ## Which directory `go build` puts the compiled code into? @@ -12,8 +16,12 @@ 3. $GOPATH/pkg directory 4. Into a temporary directory. -> 2. There only lives Go source-code files -> 3. Go only puts your code there when you call `go install`. +> **2:** There only lives Go source-code files +> +> +> **3:** Go only puts your code there when you call `go install`. +> +> ## Which directory `go run` puts the compiled code into? @@ -38,6 +46,12 @@ 2. While it runs (after compile-time). *CORRECT* 3. While it runs (inside the compile-time). -> 1. In the compilation step your program cannot print a message. In that stage, it's literally dead. -> 2. That's right. That's the only time which your program can interact with a computer and instruct it to print a message to the console. -> 3. Running can only happen after the compile-time \ No newline at end of file +> **1:** In the compilation step your program cannot print a message. In that stage, it's literally dead. +> +> +> **2:** That's right. That's the only time which your program can interact with a computer and instruct it to print a message to the console. +> +> +> **3:** Running can only happen after the compile-time +> +> \ No newline at end of file