A mirror of my website's source code.

By using this site, you agree to have cookies stored on your device, strictly for functional purposes, such as storing your session and preferences.

Dismiss

Revised FizzBuzz again

steve0greatness,
created on Saturday, 3 February 2024, 06:11:03 (1706940663), received on Monday, 6 May 2024, 02:55:37 (1714964137)
Author identity: Steve0Greatness <steve0greatnessiscool@gmail.com>

56d8a4bd7645cfc87779928f43d3096e691d7a77

.gitignore

@@ -1,2 +1,3 @@

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            __pycache__
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        build
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        build
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        *.ignore
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                            
                                

blog-posts/fizzbuzz.md

@@ -1,7 +1,7 @@

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            ---
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            title: The FizzBuzz Program
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            date: 2022 Feb 20
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        updated: 2024 Jan 17
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        updated: 2024 Feb 2
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            ---
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            A FizzBuzz Program is a program used in many job interviews to see if a programmer is good at problem solving. There are many ways to make one.
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        

@@ -10,33 +10,134 @@ First let me tell you why I write these programs. These programs, at least in my

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            Now that I've told you what a FizzBuzz Program is, let me show you how I make them in Python.
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            ```python
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        for i in range(1, 100):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            toPrint = ""
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            print(toPrint)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        for Index in range(1, 100):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            Response = ""
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            print(Response)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            ```
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            The first thing I do is I create a for loop, and within it I put a print statement and a variable named toPrint.
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            ```python
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        def check(checktomulti, multi, toreturn):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            if checktomulti % multi == 0:
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                return toreturn
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            return ""
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        def checkEmpty(string, number):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            if string == "":
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                return number
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            return string
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        def FizzCompute(Number, Divisor, String):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            return String if Number % Divisor == 0 else ""
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        def SubstituteEmpty(String, Number):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            return String if String != "" else Number
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        for i in range(1, 100):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            toPrint = checkEmpty(check(i, 3, "Fizz") + check(i, 5, "Buzz"), i)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            print(toPrint)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        for Index in range(1, 100):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            Response = SubstituteEmpty(FizzCompute(Index, 3, "Fizz") + FizzCompute(Index, 5, "Buzz"), Index)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            print(Response)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        ```
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        <details>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            <summary>Output</summary>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            ```
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        1
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        2
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        4
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Buzz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        7
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        8
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Buzz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        11
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        13
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        14
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        FizzBuzz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        16
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        17
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        19
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Buzz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        22
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        23
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Buzz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        26
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        28
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        29
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        FizzBuzz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        31
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        32
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        34
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Buzz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        37
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        38
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Buzz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        41
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        43
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        44
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        FizzBuzz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        46
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        47
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        49
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Buzz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        52
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        53
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Buzz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        56
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        58
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        59
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        FizzBuzz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        61
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        62
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        64
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Buzz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        67
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        68
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Buzz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        71
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        73
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        74
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        FizzBuzz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        76
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        77
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        79
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Buzz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        82
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        83
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Buzz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        86
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        88
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        89
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        FizzBuzz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        91
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        92
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        94
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Buzz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        97
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        98
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Fizz
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        ```
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        </details>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            The next thing I do is I define a function that checks if one number is a multiple of another, and if it is, then it returns the string, otherwise, it returns an empty string.
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            Then I make a function that checks if a string is an empty one, if it is, then it returns a number.
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Once I have these 2 functions, I go back into the for loop and make the `toPrint` variable have the variable for checking if a string is empty(and if it is replace it with a number) check if 2 of the other function that check if one number is a multiple of another(and if it is, return a string). Finally, it prints the output.
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        Once I have these 2 functions, I go back into the for loop and make the `Response` variable have the variable for checking if a string is empty(and if it is replace it with a number) check if 2 of the other function that check if one number is a multiple of another(and if it is, return a string). Finally, it prints the output.
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            I've tried this method many times. Below are some examples of this method in action!