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

  1. package main
  2. import (
  3. "errors"
  4. "fmt"
  5. )
  6. func validate(input int) error {
  7. if input < 0 {
  8. return errors.New("input can't be a negatice number")
  9. } else if input > 100 {
  10. return errors.New("input can't be over 100")
  11. } else if input%7 == 0 {
  12. return errors.New("input can't be divisible by 7")
  13. } else {
  14. return nil
  15. }
  16. }
  17. func main() {
  18. input := 21
  19. if err := validate(input); err != nil {
  20. fmt.Println(err)
  21. } else if input%2 == 0 {
  22. fmt.Println(input, "is even")
  23. } else {
  24. fmt.Println(input, "is odd")
  25. }
  26. }