refactor: variables/assignment exercises and questions
This commit is contained in:
@ -10,7 +10,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt" // You should replace this with your username
|
"fmt" // You should replace this with your username
|
||||||
|
|
||||||
"github.com/inancgumus/learngo/05-write-your-first-library-package/printer-exercise/solution/golang"
|
"github.com/inancgumus/learngo/05-write-your-first-library-package/exercise/solution/golang"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -8,10 +8,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// EXERCISE
|
// EXERCISE: Make It Blue
|
||||||
// 1- Change `color` variable's value to "blue"
|
|
||||||
//
|
//
|
||||||
// 2- Print it
|
// 1. Change `color` variable's value to "blue"
|
||||||
|
//
|
||||||
|
// 2. Print it
|
||||||
//
|
//
|
||||||
// EXPECTED OUTPUT
|
// EXPECTED OUTPUT
|
||||||
// blue
|
// blue
|
@ -8,25 +8,27 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// EXERCISE
|
// EXERCISE: Variables To Variables
|
||||||
// 1- Change the value of `color` variable to "dark green"
|
|
||||||
//
|
//
|
||||||
// 2- Do not assign "dark green" to `color` directly
|
// 1. Change the value of `color` variable to "dark green"
|
||||||
|
//
|
||||||
|
// 2. Do not assign "dark green" to `color` directly
|
||||||
//
|
//
|
||||||
// Instead, use the `color` variable again
|
// Instead, use the `color` variable again
|
||||||
// while assigning to `color`
|
// while assigning to `color`
|
||||||
//
|
//
|
||||||
// 3- Print it
|
// 3. Print it
|
||||||
//
|
//
|
||||||
// RESTRICTIONS
|
// RESTRICTIONS
|
||||||
// WRONG ANSWER, DO NOT DO THIS:
|
// WRONG ANSWER, DO NOT DO THIS:
|
||||||
// `color = "dark green"`
|
// `color = "dark green"`
|
||||||
//
|
//
|
||||||
// HINT
|
// HINT
|
||||||
// + operator can concatenate string values
|
// + operator can concatenate string values
|
||||||
//
|
//
|
||||||
// Example:
|
// Example:
|
||||||
// "h" + "e" + "y" returns "hey"
|
//
|
||||||
|
// "h" + "e" + "y" returns "hey"
|
||||||
//
|
//
|
||||||
// EXPECTED OUTPUT
|
// EXPECTED OUTPUT
|
||||||
// dark green
|
// dark green
|
@ -10,10 +10,11 @@ package main
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// EXERCISE
|
// EXERCISE: Assign With Expressions
|
||||||
// 1- Multiply 3.14 with 2 and assign it to `n` variable
|
|
||||||
//
|
//
|
||||||
// 2- Print the `n` variable
|
// 1. Multiply 3.14 with 2 and assign it to `n` variable
|
||||||
|
//
|
||||||
|
// 2. Print the `n` variable
|
||||||
//
|
//
|
||||||
// HINT
|
// HINT
|
||||||
// Example: 3 * 2 = 6
|
// Example: 3 * 2 = 6
|
@ -8,14 +8,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// EXERCISE
|
// EXERCISE: Find the Rectangle's Area
|
||||||
// 1- Find the length of a rectangle
|
//
|
||||||
|
// 1. Find the length of a rectangle
|
||||||
// Its width is 5
|
// Its width is 5
|
||||||
// Its height is 6
|
// Its height is 6
|
||||||
//
|
//
|
||||||
// 2- Assign the result to the `length` variable
|
// 2. Assign the result to the `length` variable
|
||||||
//
|
//
|
||||||
// 3- Print the `length` variable
|
// 3. Print the `length` variable
|
||||||
//
|
//
|
||||||
// HINT
|
// HINT
|
||||||
// Rectangle formula = 2 * (width + height)
|
// Rectangle formula = 2 * (width + height)
|
@ -10,12 +10,13 @@ package main
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// EXERCISE
|
// EXERCISE: Multi Assign
|
||||||
// 1- Assign "go" to `lang` variable
|
//
|
||||||
|
// 1. Assign "go" to `lang` variable
|
||||||
// and assign 2 to `version` variable
|
// and assign 2 to `version` variable
|
||||||
// using a multiple assignment statement
|
// using a multiple assignment statement
|
||||||
//
|
//
|
||||||
// 2- Print the variables
|
// 2. Print the variables
|
||||||
//
|
//
|
||||||
// EXPECTED OUTPUT
|
// EXPECTED OUTPUT
|
||||||
// go version 2
|
// go version 2
|
@ -8,11 +8,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// EXERCISE
|
// EXERCISE: Multi Assign #2
|
||||||
// 1- Assign the correct values to the variables
|
//
|
||||||
|
// 1. Assign the correct values to the variables
|
||||||
// to match to the EXPECTED OUTPUT below
|
// to match to the EXPECTED OUTPUT below
|
||||||
//
|
//
|
||||||
// 2- Print the variables
|
// 2. Print the variables
|
||||||
//
|
//
|
||||||
// HINT
|
// HINT
|
||||||
// Use multiple Println calls to print each sentence.
|
// Use multiple Println calls to print each sentence.
|
@ -8,14 +8,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// EXERCISE
|
// EXERCISE: Multi Short Func
|
||||||
// 1- Multiple short declare two variables
|
|
||||||
//
|
//
|
||||||
// 2- Initialize variables using `multi` function below
|
// 1. Multiple short declare two variables
|
||||||
//
|
//
|
||||||
// 3- Discard the 1st variable's value in the declaration
|
// 2. Initialize variables using `multi` function below
|
||||||
//
|
//
|
||||||
// 4- Print only the 2nd variable
|
// 3. Discard the 1st variable's value in the declaration
|
||||||
|
//
|
||||||
|
// 4. Print only the 2nd variable
|
||||||
//
|
//
|
||||||
// NOTE
|
// NOTE
|
||||||
// You should use `multi` function
|
// You should use `multi` function
|
@ -8,13 +8,14 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// EXERCISE
|
// EXERCISE: Swapper
|
||||||
// 1- Change `color` to "orange"
|
//
|
||||||
|
// 1. Change `color` to "orange"
|
||||||
// and `color2` to "green" at the same time
|
// and `color2` to "green" at the same time
|
||||||
//
|
//
|
||||||
// (use multiple-assignment)
|
// (use multiple-assignment)
|
||||||
//
|
//
|
||||||
// 2- Print the variables
|
// 2. Print the variables
|
||||||
//
|
//
|
||||||
// EXPECTED OUTPUT
|
// EXPECTED OUTPUT
|
||||||
// orange green
|
// orange green
|
@ -8,10 +8,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// EXERCISE
|
// EXERCISE: Swapper #2
|
||||||
// 1- Swap the values of `red` and `blue` variables
|
|
||||||
//
|
//
|
||||||
// 2- Print them
|
// 1. Swap the values of `red` and `blue` variables
|
||||||
|
//
|
||||||
|
// 2. Print them
|
||||||
//
|
//
|
||||||
// EXPECTED OUTPUT
|
// EXPECTED OUTPUT
|
||||||
// blue red
|
// blue red
|
@ -8,10 +8,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// EXERCISE
|
// EXERCISE: Discard The File
|
||||||
// Print only the directory using `path.Split`
|
|
||||||
//
|
//
|
||||||
// Discard the file part
|
// 1. Print only the directory using `path.Split`
|
||||||
|
//
|
||||||
|
// 2. Discard the file part
|
||||||
//
|
//
|
||||||
// RESTRICTION
|
// RESTRICTION
|
||||||
// Use short declaration
|
// Use short declaration
|
25
06-variables/04-assignment/exercises/README.md
Normal file
25
06-variables/04-assignment/exercises/README.md
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# Assignments
|
||||||
|
|
||||||
|
Assignment means "copying" values. Everything is get copied in Go. You'll learn more about this afterwards.
|
||||||
|
|
||||||
|
Now, get your feet wet and try some assignment exercises.
|
||||||
|
|
||||||
|
1. **[Make It Blue](https://github.com/inancgumus/learngo/tree/master/06-variables/04-assignment/exercises/01-make-it-blue)**
|
||||||
|
|
||||||
|
2. **[Variables To Variables](https://github.com/inancgumus/learngo/tree/master/06-variables/04-assignment/exercises/02-vars-to-vars)**
|
||||||
|
|
||||||
|
3. **[Assign With Expressions](https://github.com/inancgumus/learngo/tree/master/06-variables/04-assignment/exercises/03-assign-with-expressions)**
|
||||||
|
|
||||||
|
4. **[Find the Rectangle's Area](https://github.com/inancgumus/learngo/tree/master/06-variables/04-assignment/exercises/04-find-the-rectangle-area)**
|
||||||
|
|
||||||
|
5. **[Multi Assign](https://github.com/inancgumus/learngo/tree/master/06-variables/04-assignment/exercises/05-multi-assign)**
|
||||||
|
|
||||||
|
6. **[Multi Assign #2](https://github.com/inancgumus/learngo/tree/master/06-variables/04-assignment/exercises/06-multi-assign-2)**
|
||||||
|
|
||||||
|
7. **[Multi Short Func](https://github.com/inancgumus/learngo/tree/master/06-variables/04-assignment/exercises/07-multi-short-func)**
|
||||||
|
|
||||||
|
8. **[Swapper](https://github.com/inancgumus/learngo/tree/master/06-variables/04-assignment/exercises/08-swapper)**
|
||||||
|
|
||||||
|
9. **[Swapper #2](https://github.com/inancgumus/learngo/tree/master/06-variables/04-assignment/exercises/09-swapper-2)**
|
||||||
|
|
||||||
|
10. **[Discard The File](https://github.com/inancgumus/learngo/tree/master/06-variables/04-assignment/exercises/10-discard-the-file)**
|
Reference in New Issue
Block a user