vkorbes / aprendago

Curso completo em português da linguagem Go, de zero a ninja! 🇧🇷
http://aprendago.com
1k stars 179 forks source link

Exercício: Capítulo 7, Exercício 6 (Nível: 3) #22

Open vkorbes opened 3 years ago

vkorbes commented 3 years ago

Exercício: Capítulo 7, Exercício 6 (Nível: 3)

Link para o vídeo:

Use esta thread para compartilhar sua solução, discutir o exercício com os colegas e pedir ajuda caso tenha dificuldades!

diegoparra commented 3 years ago

https://play.golang.org/p/7ukbORRgxS1

thiagoalgo commented 3 years ago

https://play.golang.org/p/XHcq9UXLtJs

viniciussanchez commented 3 years ago

https://play.golang.org/p/hak6xBjd_ME

tomxdev commented 3 years ago
package main

import "fmt"

func main() {
    x := true

    if x == true {
        fmt.Println(x)
    }
}
an4kein commented 3 years ago

https://play.golang.org/p/-J0H_0SRrMu

ygorsimoes commented 3 years ago

OBS: Por algum motivo e eu não sei qual, eu acabei me empolguei um pouco, hehe! <3

package main

import (
    "fmt"
    //"os"
    "strings"
)

/*
    JOGO: Acerte a fruta!
*/

func main() {

    /*
        // Declara uma variável do tipo string
        var fruta string

        // Entrada de dados
        _, err := fmt.Scan(&fruta)

        // Trata o erro do método Scan()
        if err != nil {
            // Encerra o programa com o valor diferente de 0
            os.Exit(-1)
        }

        // Converte a string para caixa baixa (minúsculo)
    */

    fruta := "cevreja"
    fruta = strings.ToLower(fruta)

    // Condição que verifica qual é a fruta da variável.
    if fruta == "maçã" {
        fmt.Println("Errado, maçã não é a fruta! =)")
    } else if fruta == "amora" {
        fmt.Println("Errado, amora não é a fruta! :D")
    } else if fruta == "cereja" {
        fmt.Println("Errado, cereja não é a fruta! :O")
    } else if fruta == "laranja" {
        fmt.Println("Acertou! A fruta é laranja! :)")
    } else {
        fmt.Println("Errado,", fruta, "não é a fruta!")
    }
}

Output:

Errado, cereja não é a fruta! :O
JPauloMoura commented 3 years ago
package main

//Crie um programa que demonstre o funcionamento da declaração if.
import "fmt"

func main() {
    fmt.Print("Bom dia! ")

    if eDomingo := false; eDomingo {
        fmt.Print("Hoje é Domingo!")
    }
}

Resolução do Exercício

Lucasmirandar commented 3 years ago

package main

import "fmt"

func main() { x := 10 if x == 10 { fmt.Println("X = 10") } }

andersoncleyson commented 2 years ago
package main

import "fmt"

func main(){
    x := 15
    if x < 18{
        fmt.Printf("Esse filme não é para menores de 18\n")
    }
}
CarlosSMA commented 2 years ago
package main

import (
    "fmt"
)

func main() {
    numero1 := 2
    numero2 := 3
    numero3 := 4

    // Este algoritmo irá retornar um print somente se um valor i do loop for divísivel por uma variável respectiva
    // É importante perceber que um numéro pode ser divisível por mais valores, por isto não é bom colocar a sintaxe if-else, pois ela só iria retornar um único valor possível
    // Ex.: 8 é divisível por 2 E 4, numa relação if-else, ele só poderia ser divsível por 2 OU 4
    for i := 1; i <= 10; i++ {
        if i%numero1 == 0 {
            fmt.Println("Número", i, " é divisível por 2")
        }
        if i%numero2 == 0 {
            fmt.Println("Número", i, " é divisível por 3")
        }
        if i%numero3 == 0 {
            fmt.Println("Número", i, " é divisível por 4")
        }
    }
}

Saída

Número 2  é divisível por 2
Número 3  é divisível por 3
Número 4  é divisível por 2
[...]
CaueFarias commented 2 years ago

https://go.dev/play/p/Jy6tpDiD3yv

wfrsilva commented 2 years ago

https://go.dev/play/p/kj1sgf2aHLb

image

M3L1M commented 1 year ago

s := "Gabriel"

if s == "Gabriel" {
    fmt.Println("Que nome legal")
}
adelsonsljunior commented 1 year ago
package main

import (
    "fmt"
)

func main() {

    x := true

    if x {
        fmt.Println("É verdadeiro!")
    } else {
        fmt.Println("É falso!")
    }

}
DominMFD commented 2 months ago

https://go.dev/play/p/FCiEMoc3i4i

Vitor-Zen commented 4 weeks ago

https://go.dev/play/p/oIi0cfc071z