129 lines
1.7 KiB
Go
129 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"curso-goland/mathutil"
|
|
"errors"
|
|
"fmt"
|
|
"math"
|
|
)
|
|
|
|
const GrauCelsius = 273.15
|
|
|
|
const (
|
|
A = 1
|
|
B = 2
|
|
)
|
|
|
|
func main() {
|
|
fmt.Println("Hello, World!")
|
|
|
|
fmt.Println(mathutil.Add(1, 2))
|
|
|
|
fmt.Println(math.Sqrt(144))
|
|
|
|
var x int = 10
|
|
x = x + 1
|
|
fmt.Println(x)
|
|
|
|
var a, b int = 1, 2
|
|
c := a + b
|
|
fmt.Println(c)
|
|
|
|
nombre, edad := "Juan", 30
|
|
fmt.Println(nombre, edad)
|
|
|
|
fmt.Println(mathutil.EulersNumber)
|
|
|
|
fmt.Println(math.Pi)
|
|
|
|
fmt.Println(GrauCelsius)
|
|
|
|
fmt.Println(A + B)
|
|
|
|
decirHola()
|
|
|
|
fmt.Println(sumar(6, 8))
|
|
|
|
division, err := dividir(6, 0)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
fmt.Println(division)
|
|
|
|
// La primera parte crea la y, la segunda la compara
|
|
if y := 10; y > 5 {
|
|
fmt.Println(y)
|
|
}
|
|
|
|
number := 0
|
|
if number < 0 {
|
|
fmt.Println("Es negativo")
|
|
} else if number > 0 {
|
|
fmt.Println("Es positivo")
|
|
} else {
|
|
fmt.Println("Es cero")
|
|
}
|
|
|
|
for i := 0; i < 3; i++ {
|
|
fmt.Println(i)
|
|
}
|
|
|
|
nums := []int{1, 2, 3}
|
|
|
|
for _, num := range nums {
|
|
fmt.Println(num)
|
|
}
|
|
|
|
for idx, num := range nums {
|
|
fmt.Println(idx, "-> ", num)
|
|
}
|
|
|
|
day := 3
|
|
switch day {
|
|
case 1:
|
|
fmt.Println("Lunes")
|
|
case 2:
|
|
fmt.Println("Martes")
|
|
case 3:
|
|
fmt.Println("Miercoles")
|
|
default:
|
|
fmt.Println("No es un dia valido")
|
|
}
|
|
|
|
letra := 'a'
|
|
switch letra {
|
|
case 'a', 'e', 'i', 'o', 'u':
|
|
fmt.Println("Vocal")
|
|
default:
|
|
fmt.Println("Consonante")
|
|
}
|
|
|
|
numero := 1
|
|
switch numero {
|
|
case 0:
|
|
case 1:
|
|
fmt.Println("Es cero o uno")
|
|
case 2:
|
|
fmt.Println("Dos")
|
|
default:
|
|
fmt.Println("No es un numero valido")
|
|
}
|
|
}
|
|
|
|
// Fin main
|
|
|
|
func decirHola() {
|
|
fmt.Println("Hola")
|
|
}
|
|
|
|
func sumar(a, b int) int {
|
|
return a + b
|
|
}
|
|
|
|
func dividir(a, b int) (int, error) {
|
|
if b <= 0 {
|
|
return 0, errors.New("b debe ser mayor a 0")
|
|
}
|
|
return a / b, nil
|
|
}
|