refactor: variables/assignment exercises and questions
This commit is contained in:
@ -10,7 +10,7 @@ package main
|
||||
import (
|
||||
"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() {
|
||||
|
@ -8,10 +8,11 @@
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE
|
||||
// 1- Change `color` variable's value to "blue"
|
||||
// EXERCISE: Make It Blue
|
||||
//
|
||||
// 2- Print it
|
||||
// 1. Change `color` variable's value to "blue"
|
||||
//
|
||||
// 2. Print it
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// blue
|
@ -8,25 +8,27 @@
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE
|
||||
// 1- Change the value of `color` variable to "dark green"
|
||||
// EXERCISE: Variables To Variables
|
||||
//
|
||||
// 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
|
||||
// while assigning to `color`
|
||||
//
|
||||
// 3- Print it
|
||||
// 3. Print it
|
||||
//
|
||||
// RESTRICTIONS
|
||||
// WRONG ANSWER, DO NOT DO THIS:
|
||||
// `color = "dark green"`
|
||||
// WRONG ANSWER, DO NOT DO THIS:
|
||||
// `color = "dark green"`
|
||||
//
|
||||
// HINT
|
||||
// + operator can concatenate string values
|
||||
// + operator can concatenate string values
|
||||
//
|
||||
// Example:
|
||||
// "h" + "e" + "y" returns "hey"
|
||||
// Example:
|
||||
//
|
||||
// "h" + "e" + "y" returns "hey"
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// dark green
|
@ -10,10 +10,11 @@ package main
|
||||
import "fmt"
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE
|
||||
// 1- Multiply 3.14 with 2 and assign it to `n` variable
|
||||
// EXERCISE: Assign With Expressions
|
||||
//
|
||||
// 2- Print the `n` variable
|
||||
// 1. Multiply 3.14 with 2 and assign it to `n` variable
|
||||
//
|
||||
// 2. Print the `n` variable
|
||||
//
|
||||
// HINT
|
||||
// Example: 3 * 2 = 6
|
@ -8,14 +8,15 @@
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE
|
||||
// 1- Find the length of a rectangle
|
||||
// EXERCISE: Find the Rectangle's Area
|
||||
//
|
||||
// 1. Find the length of a rectangle
|
||||
// Its width is 5
|
||||
// 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
|
||||
// Rectangle formula = 2 * (width + height)
|
@ -10,12 +10,13 @@ package main
|
||||
import "fmt"
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE
|
||||
// 1- Assign "go" to `lang` variable
|
||||
// EXERCISE: Multi Assign
|
||||
//
|
||||
// 1. Assign "go" to `lang` variable
|
||||
// and assign 2 to `version` variable
|
||||
// using a multiple assignment statement
|
||||
//
|
||||
// 2- Print the variables
|
||||
// 2. Print the variables
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// go version 2
|
@ -8,11 +8,12 @@
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE
|
||||
// 1- Assign the correct values to the variables
|
||||
// EXERCISE: Multi Assign #2
|
||||
//
|
||||
// 1. Assign the correct values to the variables
|
||||
// to match to the EXPECTED OUTPUT below
|
||||
//
|
||||
// 2- Print the variables
|
||||
// 2. Print the variables
|
||||
//
|
||||
// HINT
|
||||
// Use multiple Println calls to print each sentence.
|
@ -8,14 +8,15 @@
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE
|
||||
// 1- Multiple short declare two variables
|
||||
// EXERCISE: Multi Short Func
|
||||
//
|
||||
// 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
|
||||
// You should use `multi` function
|
@ -8,13 +8,14 @@
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE
|
||||
// 1- Change `color` to "orange"
|
||||
// EXERCISE: Swapper
|
||||
//
|
||||
// 1. Change `color` to "orange"
|
||||
// and `color2` to "green" at the same time
|
||||
//
|
||||
// (use multiple-assignment)
|
||||
//
|
||||
// 2- Print the variables
|
||||
// 2. Print the variables
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// orange green
|
@ -8,10 +8,11 @@
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE
|
||||
// 1- Swap the values of `red` and `blue` variables
|
||||
// EXERCISE: Swapper #2
|
||||
//
|
||||
// 2- Print them
|
||||
// 1. Swap the values of `red` and `blue` variables
|
||||
//
|
||||
// 2. Print them
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// blue red
|
@ -8,10 +8,11 @@
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE
|
||||
// Print only the directory using `path.Split`
|
||||
// EXERCISE: Discard The File
|
||||
//
|
||||
// Discard the file part
|
||||
// 1. Print only the directory using `path.Split`
|
||||
//
|
||||
// 2. Discard the file part
|
||||
//
|
||||
// RESTRICTION
|
||||
// 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