Exercises & activities from the go workshop provided by Packt: https://courses.packtpub.com/courses/go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

34 lines
550 B

package main
import (
"errors"
"fmt"
)
func validate(input int) error {
if input < 0 {
return errors.New("input can't be a negatice number")
} else if input > 100 {
return errors.New("input can't be over 100")
} else if input%7 == 0 {
return errors.New("input can't be divisible by 7")
} else {
return nil
}
}
func main() {
input := 21
if err := validate(input); err != nil {
fmt.Println(err)
} else if input%2 == 0 {
fmt.Println(input, "is even")
} else {
fmt.Println(input, "is odd")
}
}