Initial commit
This commit is contained in:
23
07-printf/exercises/01/main.go
Normal file
23
07-printf/exercises/01/main.go
Normal 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() {
|
||||
// ?
|
||||
}
|
||||
14
07-printf/exercises/01/solution/main.go
Normal file
14
07-printf/exercises/01/solution/main.go
Normal 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)
|
||||
}
|
||||
27
07-printf/exercises/02/main.go
Normal file
27
07-printf/exercises/02/main.go
Normal 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("?", ?, ?)
|
||||
}
|
||||
18
07-printf/exercises/02/solution/main.go
Normal file
18
07-printf/exercises/02/solution/main.go
Normal 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")
|
||||
}
|
||||
25
07-printf/exercises/03/main.go
Normal file
25
07-printf/exercises/03/main.go
Normal 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
|
||||
// ?
|
||||
}
|
||||
15
07-printf/exercises/03/solution/main.go
Normal file
15
07-printf/exercises/03/solution/main.go
Normal 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)
|
||||
}
|
||||
24
07-printf/exercises/04/main.go
Normal file
24
07-printf/exercises/04/main.go
Normal 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() {
|
||||
// ?
|
||||
}
|
||||
14
07-printf/exercises/04/solution/main.go
Normal file
14
07-printf/exercises/04/solution/main.go
Normal 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)
|
||||
}
|
||||
24
07-printf/exercises/05/main.go
Normal file
24
07-printf/exercises/05/main.go
Normal 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() {
|
||||
// ?
|
||||
}
|
||||
14
07-printf/exercises/05/solution/main.go
Normal file
14
07-printf/exercises/05/solution/main.go
Normal 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")
|
||||
}
|
||||
20
07-printf/exercises/06/main.go
Normal file
20
07-printf/exercises/06/main.go
Normal 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() {
|
||||
// ?
|
||||
}
|
||||
14
07-printf/exercises/06/solution/main.go
Normal file
14
07-printf/exercises/06/solution/main.go
Normal 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)
|
||||
}
|
||||
20
07-printf/exercises/07/main.go
Normal file
20
07-printf/exercises/07/main.go
Normal 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() {
|
||||
// ?
|
||||
}
|
||||
14
07-printf/exercises/07/solution/main.go
Normal file
14
07-printf/exercises/07/solution/main.go
Normal 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)
|
||||
}
|
||||
20
07-printf/exercises/08/main.go
Normal file
20
07-printf/exercises/08/main.go
Normal 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() {
|
||||
// ?
|
||||
}
|
||||
14
07-printf/exercises/08/solution/main.go
Normal file
14
07-printf/exercises/08/solution/main.go
Normal 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")
|
||||
}
|
||||
20
07-printf/exercises/09/main.go
Normal file
20
07-printf/exercises/09/main.go
Normal 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() {
|
||||
// ?
|
||||
}
|
||||
14
07-printf/exercises/09/solution/main.go
Normal file
14
07-printf/exercises/09/solution/main.go
Normal 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)
|
||||
}
|
||||
24
07-printf/exercises/10/main.go
Normal file
24
07-printf/exercises/10/main.go
Normal 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
|
||||
}
|
||||
23
07-printf/exercises/10/solution/main.go
Normal file
23
07-printf/exercises/10/solution/main.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user