diff options
author | Kyle K <kylek389@gmail.com> | 2022-08-03 00:31:39 -0500 |
---|---|---|
committer | Kyle K <kylek389@gmail.com> | 2022-08-03 00:35:14 -0500 |
commit | b01d896f8699b1c96a98d8c21e748403659f92d3 (patch) | |
tree | 7bb36342e5f27deac27225ce0ed35381298e29e7 /fizzbuzz.py | |
parent | a6ec4b92d10e19992f5ba603c25587141782b746 (diff) | |
download | PythonPractice-b01d896f8699b1c96a98d8c21e748403659f92d3.tar.gz PythonPractice-b01d896f8699b1c96a98d8c21e748403659f92d3.tar.bz2 PythonPractice-b01d896f8699b1c96a98d8c21e748403659f92d3.zip |
fizzbuzz
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 |