Skip to content

Commit 9cadc74

Browse files
committed
solve(learngo): some tasks
solved tasks: - 02-write-your-first-program - 03-packages-and-scopes - 04-statements-expressions-comments
1 parent 33b0d6c commit 9cadc74

File tree

35 files changed

+122
-336
lines changed

35 files changed

+122
-336
lines changed

collections/learngo/02-write-your-first-program/exercises/01-print-names/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
package main
1010

11+
import "fmt"
12+
1113
// ---------------------------------------------------------
1214
// EXERCISE: Print names
1315
//
@@ -24,6 +26,6 @@ package main
2426
// ---------------------------------------------------------
2527

2628
func main() {
27-
// ?
28-
// ?
29+
fmt.Println("Slaweak")
30+
fmt.Println("World")
2931
}

collections/learngo/02-write-your-first-program/exercises/01-print-names/solution/main.go

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
## Where should you save your Go source code?
22
* Anywhere on my computer
33
* Under $GOPATH
4-
* Under $GOPATH/src
4+
* Under $GOPATH/src *CORRECT*
55

66
## What does $GOPATH mean?
77
* It's a file for Go runtime
8-
* Stores Go source code files and compiled packages
8+
* Stores Go source code files and compiled packages *CORRECT*
99
* It's a path for gophers to follow
1010

1111
## Do you need to set $GOPATH?
1212
* Yes
1313
* No: It's stored on my desktop
14-
* No: It's stored under my user path
14+
* No: It's stored under my user path *CORRECT*
1515

1616
## How can you print $GOPATH?
1717
* Using `ls` command
18-
* Using `go env GOPATH` command
18+
* Using `go env GOPATH` command *CORRECT*
1919
* Using `go environment` command

collections/learngo/02-write-your-first-program/questions/02-code-your-first-program/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ func main() {
66
}
77
```
88
1. func
9-
2. package
9+
2. package *CORRECT*
1010
3. fmt.Println
1111
4. import
1212

@@ -33,7 +33,7 @@ func main() {
3333
```
3434
* To create a library package
3535
* To properly exit from the program
36-
* To create an executable Go program
36+
* To create an executable Go program *CORRECT*
3737

3838

3939
## What is the purpose of func main in the following program?
@@ -44,8 +44,8 @@ func main() {
4444
}
4545
```
4646
1. It defines a package called main
47-
2. It allows Go to start executing the program
48-
3. It prints a message to the console
47+
2. It allows Go to start executing the program *CORRECT*
48+
3. It prints a message to the console *CORRECT*
4949

5050
> **1:** main function doesn't create a package.
5151
>
@@ -83,14 +83,14 @@ func main() {
8383
8484

8585
## Which keyword is used to declare a new function?
86-
* func
86+
* func *CORRECT*
8787
* package
8888
* Println
8989
* import
9090

9191

9292
## What is a function?
93-
1. It's like a mini-program. It's a reusable and executable block of code.
93+
1. It's like a mini-program. It's a reusable and executable block of code. *CORRECT*
9494
2. It allows Go to execute a program.
9595
3. It allows Go to import a package called function.
9696
4. It prints a message to the console.
@@ -108,7 +108,7 @@ func main() {
108108

109109
## Do you have to call the main function yourself?
110110
1. Yes, so that, I can execute my program.
111-
2. No, Go calls the main function automatically.
111+
2. No, Go calls the main function automatically. *CORRECT*
112112

113113
> **1:** No, you don't need to call the main function. Go automatically executes it.
114114
>
@@ -117,7 +117,7 @@ func main() {
117117

118118
## Do you have to call a function to execute it?
119119
_(except the main func)_
120-
1. Yes, so that, Go can execute that function.
120+
1. Yes, so that, Go can execute that function. *CORRECT*
121121
2. Yes, so that, Go can execute my program.
122122
3. No, Go calls the functions automatically.
123123

@@ -141,7 +141,7 @@ func main() {
141141
}
142142
```
143143
1. It prints a message to the console
144-
2. It's a correct program but it doesn't print anything
144+
2. It's a correct program but it doesn't print anything *CORRECT*
145145
3. It's an incorrect program
146146

147147
> **1:** It doesn't print a message. To do that you can use fmt.Println function.
@@ -167,7 +167,7 @@ func main() {
167167
```
168168
* Hi! I want to be a Gopher!
169169
* It doesn't print anything
170-
* This program is incorrect
170+
* This program is incorrect *CORRECT*
171171

172172
> **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")
173173
>
@@ -187,7 +187,7 @@ func main() {
187187
fmt.Println("Hi there!")
188188
}
189189
```
190-
* Hi there!
190+
* Hi there! *CORRECT*
191191
* fmt
192192
* This program is incorrect; it imports the wrong package or there isn't a function called `Println`
193193

collections/learngo/02-write-your-first-program/questions/03-run-your-first-program/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## What is the difference between `go build` and `go run`?
2-
1. `go run` just compiles a program; whereas `go build` both compiles and runs it.
3-
2. `go run` both compiles and runs a program; whereas `go build` just compiles it.
2+
1. `go run` just compiles a program; whereas `go build` both compiles and runs it.
3+
2. `go run` both compiles and runs a program; whereas `go build` just compiles it. *CORRECT*
44

55
> **1:** It's opposite actually.
66
>
@@ -11,7 +11,7 @@
1111
1212

1313
## Go saves the compiled code in a directory. What is the name of that directory?
14-
1. The same directory where you call `go build`
14+
1. The same directory where you call `go build` *CORRECT*
1515
2. $GOPATH/src directory
1616
3. $GOPATH/pkg directory
1717
4. Into a temporary directory.
@@ -25,18 +25,18 @@
2525
2626

2727
## Which is true for runtime?
28-
1. It happens when your program starts running on a computer
28+
1. It happens when your program starts running on a computer *CORRECT*
2929
2. It happens while your program is being compiled
3030

3131

3232
## Which is true for the compile-time?
3333
1. It happens when your program starts running on a computer
34-
2. It happens while your program is being compiled
34+
2. It happens while your program is being compiled *CORRECT*
3535

3636

3737
## When can a Go program print a message to the console?
3838
1. While it's being compiled.
39-
2. While it runs (after compile-time).
39+
2. While it runs (after compile-time). *CORRECT*
4040
3. While it runs (inside the compile-time).
4141

4242
> **1:** In the compilation step your program cannot print a message. In that stage, it's literally dead.

collections/learngo/03-packages-and-scopes/02-scopes/04-package-scope/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ func main() {
2121
// EXERCISE: Remove the comments from the below function
2222
// And analyze the error message
2323

24-
// func bye() {
25-
// fmt.Println("Bye!")
26-
// }
24+
//func bye() {
25+
// fmt.Println("Bye!")
26+
//}
2727

2828
// ***** EXPLANATION *****
2929
//
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func bye() {
6+
fmt.Println("goodbye")
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func greet() {
6+
fmt.Println("Hi there")
7+
}

collections/learngo/03-packages-and-scopes/exercises/01-packages/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ package main
2828
// ---------------------------------------------------------
2929

3030
func main() {
31-
// call functions of the other files here
31+
greet()
32+
bye()
3233
}

collections/learngo/03-packages-and-scopes/exercises/01-packages/solution/bye.go

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)