How to solve Fizz Buzz with Go, Python and PowerShell

I have always heard about FizzBuzz but was not really sure what it was. After some research it seems that FizzBuzz is pretty common interview question for Software Developers even though it is a children’s game.

The question goes like this:

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print Buzz. For numbers which are multiples of both three and five print FizzBuzz.

I am in Dev/Ops week in the AWS loft NY (2/22/2017) and I challenged myself to see in how many programing languages I was able to solve FizzBuzz before the first speaker finish. BTW he was talking about CHEF and AWS Opsworks and I am pretty familiar with those two technologies so no loss there.

So, it took me a little less than 30 minutes to write the solution in Go, Python and PowerShell. These are the solutions


GO


Python3

for number in range(1,101):
    if number % 3 == 0 and number % 5 == 0:
        print('FizzBuzz')
    elif number % 3 == 0:
        print('Fizz')
    elif number % 5 ==0:
        print('Buzz')
    else:
        print(number)

PowerShell

ForEach ($number in (1..100)) {

    if($number % 3 -eq 0 -and $number % 5 -eq 0){
        Write-Output('FizzBuzz')
    }  

    elseif ($number % 3 -eq 0) {
        Write-Output('Fizz')
    }
    elseif ($number % 5 -eq 0){
        Write-Output('Buzz')
    }

    else{
        Write-Output($number)
    }
}

Finally, if you are reading this now you can see how to solve FizzBuzz in different languages and try to solve on you prefer language. The key to solve the problem is by using the modulus operator

2 thoughts on “How to solve Fizz Buzz with Go, Python and PowerShell

  1. Daniel

    Wow you’ve been programming a lot since we first met! Kudos to you sir glad to see you’re liking it, keep up the good work.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s