Initial commit
This commit is contained in:
18
11-if/02-if-statement/01-if-branch/main.go
Normal file
18
11-if/02-if-statement/01-if-branch/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() {
|
||||
score, valid := 5, true
|
||||
|
||||
if score > 3 && valid {
|
||||
fmt.Println("good")
|
||||
}
|
||||
}
|
20
11-if/02-if-statement/02-else-branch/main.go
Normal file
20
11-if/02-if-statement/02-else-branch/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
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
score, valid := 3, true
|
||||
|
||||
if score > 3 && valid {
|
||||
fmt.Println("good")
|
||||
} else {
|
||||
fmt.Println("low")
|
||||
}
|
||||
}
|
22
11-if/02-if-statement/03-else-if-branch/01/main.go
Normal file
22
11-if/02-if-statement/03-else-if-branch/01/main.go
Normal file
@@ -0,0 +1,22 @@
|
||||
// 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() {
|
||||
score := 3
|
||||
|
||||
if score > 3 {
|
||||
fmt.Println("good")
|
||||
} else if score == 3 {
|
||||
fmt.Println("on the edge")
|
||||
} else {
|
||||
fmt.Println("low")
|
||||
}
|
||||
}
|
24
11-if/02-if-statement/03-else-if-branch/02/main.go
Normal file
24
11-if/02-if-statement/03-else-if-branch/02/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
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
score := 2
|
||||
|
||||
if score > 3 {
|
||||
fmt.Println("good")
|
||||
} else if score == 3 {
|
||||
fmt.Println("on the edge")
|
||||
} else if score == 2 {
|
||||
fmt.Println("meh...")
|
||||
} else {
|
||||
fmt.Println("low")
|
||||
}
|
||||
}
|
42
11-if/02-if-statement/04-refactor-feet-to-meters/main.go
Normal file
42
11-if/02-if-statement/04-refactor-feet-to-meters/main.go
Normal file
@@ -0,0 +1,42 @@
|
||||
// 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"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const usage = `
|
||||
Feet to Meters
|
||||
--------------
|
||||
This program converts feet into meters.
|
||||
|
||||
Usage:
|
||||
feet [feetsToConvert]`
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Println(strings.TrimSpace(usage))
|
||||
|
||||
// ALTERNATIVE:
|
||||
// fmt.Println("Please tell me a value in feet")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
arg := os.Args[1]
|
||||
|
||||
feet, _ := strconv.ParseFloat(arg, 64)
|
||||
|
||||
meters := feet * 0.3048
|
||||
|
||||
fmt.Printf("%g feet is %g meters.\n", feet, meters)
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
// 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
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// CHALLENGE #1
|
||||
// Create a user/password protected program.
|
||||
//
|
||||
// EXAMPLE USER
|
||||
// username: jack
|
||||
// password: 1888
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// go run main.go
|
||||
// Usage: [username] [password]
|
||||
//
|
||||
// go run main.go albert
|
||||
// Usage: [username] [password]
|
||||
//
|
||||
// go run main.go hacker 42
|
||||
// Access denied for "hacker".
|
||||
//
|
||||
// go run main.go jack 6475
|
||||
// Invalid password for "jack".
|
||||
//
|
||||
// go run main.go jack 1888
|
||||
// Access granted to "jack".
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
// 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() {
|
||||
args := os.Args
|
||||
|
||||
if len(args) != 3 {
|
||||
fmt.Println("Usage: [username] [password]")
|
||||
return
|
||||
}
|
||||
|
||||
u, p := args[1], args[2]
|
||||
|
||||
if u != "jack" {
|
||||
fmt.Printf("Access denied for %q.\n", u)
|
||||
} else if p != "1888" {
|
||||
fmt.Printf("Invalid password for %q.\n", u)
|
||||
} else {
|
||||
fmt.Printf("Access granted to %q.\n", u)
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
// 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"
|
||||
)
|
||||
|
||||
const (
|
||||
usage = "Usage: [username] [password]"
|
||||
errUser = "Access denied for %q.\n"
|
||||
errPwd = "Invalid password for %q.\n"
|
||||
accessOK = "Access granted to %q.\n"
|
||||
user = "jack"
|
||||
pass = "1888"
|
||||
)
|
||||
|
||||
func main() {
|
||||
args := os.Args
|
||||
|
||||
if len(args) != 3 {
|
||||
fmt.Println(usage)
|
||||
return
|
||||
}
|
||||
|
||||
u, p := args[1], args[2]
|
||||
|
||||
if u != user {
|
||||
fmt.Printf(errUser, u)
|
||||
} else if p != pass {
|
||||
fmt.Printf(errPwd, u)
|
||||
} else {
|
||||
fmt.Printf(accessOK, u)
|
||||
}
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
// 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"
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// CHALLENGE #2
|
||||
// Add one more user to the PassMe program below.
|
||||
//
|
||||
// EXAMPLE USERS
|
||||
// username: jack
|
||||
// password: 1888
|
||||
//
|
||||
// username: inanc
|
||||
// password: 1879
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// go run main.go
|
||||
// Usage: [username] [password]
|
||||
//
|
||||
// go run main.go hacker 42
|
||||
// Access denied for "hacker".
|
||||
//
|
||||
// go run main.go jack 1888
|
||||
// Access granted to "jack".
|
||||
//
|
||||
// go run main.go inanc 1879
|
||||
// Access granted to "inanc".
|
||||
//
|
||||
// go run main.go jack 1879
|
||||
// Invalid password for "jack".
|
||||
//
|
||||
// go run main.go inanc 1888
|
||||
// Invalid password for "inanc".
|
||||
// ---------------------------------------------------------
|
||||
|
||||
const (
|
||||
usage = "Usage: [username] [password]"
|
||||
errUser = "Access denied for %q.\n"
|
||||
errPwd = "Invalid password for %q.\n"
|
||||
accessOK = "Access granted to %q.\n"
|
||||
user = "jack"
|
||||
pass = "1888"
|
||||
)
|
||||
|
||||
func main() {
|
||||
args := os.Args
|
||||
|
||||
if len(args) != 3 {
|
||||
fmt.Println(usage)
|
||||
return
|
||||
}
|
||||
|
||||
u, p := args[1], args[2]
|
||||
|
||||
if u != user {
|
||||
fmt.Printf(errUser, u)
|
||||
} else if p != pass {
|
||||
fmt.Printf(errPwd, u)
|
||||
} else {
|
||||
fmt.Printf(accessOK, u)
|
||||
}
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
// 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"
|
||||
)
|
||||
|
||||
const (
|
||||
usage = "Usage: [username] [password]"
|
||||
errUser = "Access denied for %q.\n"
|
||||
errPwd = "Invalid password for %q.\n"
|
||||
accessOK = "Access granted to %q.\n"
|
||||
user, user2 = "jack", "inanc"
|
||||
pass, pass2 = "1888", "1879"
|
||||
)
|
||||
|
||||
func main() {
|
||||
args := os.Args
|
||||
|
||||
if len(args) != 3 {
|
||||
fmt.Println(usage)
|
||||
return
|
||||
}
|
||||
|
||||
u, p := args[1], args[2]
|
||||
|
||||
if u != user && u != user2 {
|
||||
fmt.Printf(errUser, u)
|
||||
} else if u == user && p == pass {
|
||||
fmt.Printf(accessOK, u)
|
||||
} else if u == user2 && p == pass2 {
|
||||
fmt.Printf(accessOK, u)
|
||||
} else {
|
||||
fmt.Printf(errPwd, u)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user