diff options
Diffstat (limited to 'fizzbuzz.py')
-rw-r--r-- | fizzbuzz.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/fizzbuzz.py b/fizzbuzz.py new file mode 100644 index 0000000..82d632c --- /dev/null +++ b/fizzbuzz.py @@ -0,0 +1,23 @@ +""" +problem: write program that prints the numbers from 1 to 100 and for any multiples of 3 print "Fizz", +for any multiple of 5 print "Buzz", and for any multiple of both 3 and 5 print "FizzBuzz" + +solution: use an if elseif elseif else statement starting with most specific case: the 3 and 5 multiple +""" +def fizzbuzz(n): + for i in range(1, n): + if i % 3 == 0 and i % 5 == 0: + print("FizzBuzz") + elif i % 3 == 0: + print("Fizz") + elif i % 5 == 0: + print("Buzz") + else: + print(i) + +def main(): + n = 100 + fizzbuzz(n) + +if __name__ == "__main__": + main()
\ No newline at end of file |