fizzbuzz python

To implement the FizzBuzz problem in the Go programming language, you can use the following code snippet:

package main

import "fmt"

func main() {
    for i := 1; i <= 100; i++ {
        if i%3 == 0 && i%5 == 0 {
            fmt.Println("FizzBuzz")
        } else if i%3 == 0 {
            fmt.Println("Fizz")
        } else if i%5 == 0 {
            fmt.Println("Buzz")
        } else {
            fmt.Println(i)
        }
    }
}

Explanation:

  • The main function is the entry point of the program.
  • The for loop iterates from 1 to 100, inclusive.
  • Inside the loop, we use conditional statements (if, else if, else) to check the divisibility of the current number (i).
  • If i is divisible by both 3 and 5, we print "FizzBuzz" using the fmt.Println() function.
  • If i is only divisible by 3, we print "Fizz".
  • If i is only divisible by 5, we print "Buzz".
  • If none of the above conditions are true, we simply print the value of i.

This code effectively solves the FizzBuzz problem in Go by printing the numbers from 1 to 100, replacing numbers divisible by 3 with "Fizz", numbers divisible by 5 with "Buzz", and numbers divisible by both 3 and 5 with "FizzBuzz".