From b01d896f8699b1c96a98d8c21e748403659f92d3 Mon Sep 17 00:00:00 2001 From: Kyle K Date: Wed, 3 Aug 2022 00:31:39 -0500 Subject: fizzbuzz --- fizzbuzz.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 fizzbuzz.py 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 -- cgit v1.2.3