From 89568a399de1f035c20f8452043d2cc937b6a366 Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Fri, 30 Sep 2022 15:47:49 +0000 Subject: [PATCH 01/26] fizzbuzz --- dynamic_programming/fizz_buzz.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 dynamic_programming/fizz_buzz.py diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py new file mode 100644 index 000000000000..bf45ba3184f6 --- /dev/null +++ b/dynamic_programming/fizz_buzz.py @@ -0,0 +1,11 @@ +#https://en.wikipedia.org/wiki/Fizz_buzz#Programming +number = 1 +out = "" +iterations = 100 + +while number <= int(iterations): + if number % 3 == 0: out += "Fizz" + if number % 5 == 0: out +="Buzz" + if out == "": out = number + print(out) + number += 1 From 05a7f02425e2ec99481c1bb732f077cda7d979b0 Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Sat, 1 Oct 2022 04:30:35 +0000 Subject: [PATCH 02/26] Update dynamic_programming/fizz_buzz.py Co-authored-by: Caeden --- dynamic_programming/fizz_buzz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py index bf45ba3184f6..48bdffce0b7c 100644 --- a/dynamic_programming/fizz_buzz.py +++ b/dynamic_programming/fizz_buzz.py @@ -3,7 +3,7 @@ out = "" iterations = 100 -while number <= int(iterations): +while number <= iterations: if number % 3 == 0: out += "Fizz" if number % 5 == 0: out +="Buzz" if out == "": out = number From 5f1bc551ee56244908e10bdaf904f0c4f56e4547 Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Sat, 1 Oct 2022 04:30:41 +0000 Subject: [PATCH 03/26] Update dynamic_programming/fizz_buzz.py Co-authored-by: Caeden --- dynamic_programming/fizz_buzz.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py index 48bdffce0b7c..ebadd655bf1e 100644 --- a/dynamic_programming/fizz_buzz.py +++ b/dynamic_programming/fizz_buzz.py @@ -4,7 +4,8 @@ iterations = 100 while number <= iterations: - if number % 3 == 0: out += "Fizz" + if number % 3 == 0: + out += "Fizz" if number % 5 == 0: out +="Buzz" if out == "": out = number print(out) From 03ca8106cc445bb9d608b073837e57b61866c1ef Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Sat, 1 Oct 2022 04:30:49 +0000 Subject: [PATCH 04/26] Update dynamic_programming/fizz_buzz.py Co-authored-by: Caeden --- dynamic_programming/fizz_buzz.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py index ebadd655bf1e..a9643ddadd53 100644 --- a/dynamic_programming/fizz_buzz.py +++ b/dynamic_programming/fizz_buzz.py @@ -6,7 +6,8 @@ while number <= iterations: if number % 3 == 0: out += "Fizz" - if number % 5 == 0: out +="Buzz" + if number % 5 == 0: + out += "Buzz" if out == "": out = number print(out) number += 1 From 3829072179d8869f759496dacecda24d5af3d3b4 Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Sat, 1 Oct 2022 04:30:54 +0000 Subject: [PATCH 05/26] Update dynamic_programming/fizz_buzz.py Co-authored-by: Caeden --- dynamic_programming/fizz_buzz.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py index a9643ddadd53..a1adc4a91367 100644 --- a/dynamic_programming/fizz_buzz.py +++ b/dynamic_programming/fizz_buzz.py @@ -8,6 +8,7 @@ out += "Fizz" if number % 5 == 0: out += "Buzz" - if out == "": out = number + if out == "": + out = number print(out) number += 1 From 48791aeff087099c1aa6558dc05c555f714a9dd2 Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Sat, 1 Oct 2022 04:31:17 +0000 Subject: [PATCH 06/26] Update dynamic_programming/fizz_buzz.py Co-authored-by: Caeden --- dynamic_programming/fizz_buzz.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py index a1adc4a91367..cb6ab7ddecfc 100644 --- a/dynamic_programming/fizz_buzz.py +++ b/dynamic_programming/fizz_buzz.py @@ -10,5 +10,6 @@ out += "Buzz" if out == "": out = number - print(out) - number += 1 +if __name__ == "__main__": + print(out) + number += 1 From e8b19c70d948af2f07cd8b8eb7a36edcba43e1d2 Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Sat, 1 Oct 2022 06:32:03 +0000 Subject: [PATCH 07/26] added doctests and function to fizzbuzz --- dynamic_programming/fizz_buzz.py | 81 ++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 10 deletions(-) diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py index cb6ab7ddecfc..ebb1fe153320 100644 --- a/dynamic_programming/fizz_buzz.py +++ b/dynamic_programming/fizz_buzz.py @@ -1,15 +1,76 @@ #https://en.wikipedia.org/wiki/Fizz_buzz#Programming -number = 1 -out = "" -iterations = 100 -while number <= iterations: - if number % 3 == 0: +def fizz_buzz(number=None,out=None,iterations=None,fizz_number=None,buzz_number=None): + """ + Plays FizzBuzz. Prints Fizz if number is a multiple of 3 and Buzz if its a multiple of 5 + Prints FizzBuzz if its a multiple of both 3 and 5 or 15. Else Prints The Number Itself. + + >>> fizz_buzz() + 1 + 2 + Fizz + 4 + Buzz + >>> fizz_buzz(1,"",7,3,5) + 1 + 2 + Fizz + 4 + Buzz + Fizz + 7 + >>> fizz_buzz(1,"",'a',3,5) + Traceback (most recent call last): + ... + ValueError: iterations must be defined as integers + >>> fizz_buzz(1,"",5,'a',5) + Traceback (most recent call last): + ... + ValueError: fizz_number must be defined as an integer + >>> fizz_buzz(1,"",5,3,'a') + Traceback (most recent call last): + ... + ValueError: buzz_number must be defined as an integer + >>> fizz_buzz(1,"",0,3,5) + Traceback (most recent call last): + ... + ValueError: iterations must be done more than 0 times to play FizzBuzz + >>> fizz_buzz('a',"",5,3,5) + Traceback (most recent call last): + ... + ValueError: starting number must be and integer and be more than 0 + + """ + if number is None and out is None and iterations is None and fizz_number is None and buzz_number is None: + number = 1 + out = "" + iterations = 5 + fizz_number = 3 + buzz_number = 5 + + if not type(iterations) == int: + raise ValueError("iterations must be defined as integers") + if not type(fizz_number) == int: + raise ValueError("fizz_number must be defined as an integer") + if not type(buzz_number) == int: + raise ValueError("buzz_number must be defined as an integer") + if not iterations >= 1: + raise ValueError("iterations must be done more than 0 times to play FizzBuzz") + if not type(number) == int or not number >= 1: + raise ValueError("starting number must be and integer and be more than 0") + + while number <= iterations: + if number % fizz_number == 0: out += "Fizz" - if number % 5 == 0: + if number % buzz_number == 0: out += "Buzz" - if out == "": - out = number + if out == "": + out = str(number) + + print(out) + number += 1 + out = "" + if __name__ == "__main__": - print(out) - number += 1 + import doctest + doctest.testmod() From 3f889bfc4c0b989eaf50e6103247db94cbe25a90 Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Sat, 1 Oct 2022 06:36:16 +0000 Subject: [PATCH 08/26] Update fizz_buzz.py --- dynamic_programming/fizz_buzz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py index ebb1fe153320..4c4bda35b615 100644 --- a/dynamic_programming/fizz_buzz.py +++ b/dynamic_programming/fizz_buzz.py @@ -1,6 +1,6 @@ #https://en.wikipedia.org/wiki/Fizz_buzz#Programming -def fizz_buzz(number=None,out=None,iterations=None,fizz_number=None,buzz_number=None): +def fizz_buzz(number=None,out=None,iterations=None,fizz_number=None,buzz_number=None) -> None: """ Plays FizzBuzz. Prints Fizz if number is a multiple of 3 and Buzz if its a multiple of 5 Prints FizzBuzz if its a multiple of both 3 and 5 or 15. Else Prints The Number Itself. From 3370d4678d457b402703e1369d1f0e5bae10f3cb Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Sat, 1 Oct 2022 06:38:35 +0000 Subject: [PATCH 09/26] Update fizz_buzz.py --- dynamic_programming/fizz_buzz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py index 4c4bda35b615..a2ed3cd87ba1 100644 --- a/dynamic_programming/fizz_buzz.py +++ b/dynamic_programming/fizz_buzz.py @@ -1,6 +1,6 @@ #https://en.wikipedia.org/wiki/Fizz_buzz#Programming -def fizz_buzz(number=None,out=None,iterations=None,fizz_number=None,buzz_number=None) -> None: +def fizz_buzz(number=None: int,out=None: str,iterations=None: int,fizz_number=None: int,buzz_number=None: int) -> None: """ Plays FizzBuzz. Prints Fizz if number is a multiple of 3 and Buzz if its a multiple of 5 Prints FizzBuzz if its a multiple of both 3 and 5 or 15. Else Prints The Number Itself. From d7c332d39ff65fa7fba9d1874cb59dd8d3698abd Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Sat, 1 Oct 2022 06:49:53 +0000 Subject: [PATCH 10/26] Fixed FizzBuzz --- dynamic_programming/fizz_buzz.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py index a2ed3cd87ba1..4c2eefaafa4c 100644 --- a/dynamic_programming/fizz_buzz.py +++ b/dynamic_programming/fizz_buzz.py @@ -1,16 +1,10 @@ #https://en.wikipedia.org/wiki/Fizz_buzz#Programming -def fizz_buzz(number=None: int,out=None: str,iterations=None: int,fizz_number=None: int,buzz_number=None: int) -> None: +def fizz_buzz(number: int,out: str,iterations: int,fizz_number: int,buzz_number: int) -> None: """ Plays FizzBuzz. Prints Fizz if number is a multiple of 3 and Buzz if its a multiple of 5 Prints FizzBuzz if its a multiple of both 3 and 5 or 15. Else Prints The Number Itself. - >>> fizz_buzz() - 1 - 2 - Fizz - 4 - Buzz >>> fizz_buzz(1,"",7,3,5) 1 2 @@ -41,12 +35,6 @@ def fizz_buzz(number=None: int,out=None: str,iterations=None: int,fizz_number=No ValueError: starting number must be and integer and be more than 0 """ - if number is None and out is None and iterations is None and fizz_number is None and buzz_number is None: - number = 1 - out = "" - iterations = 5 - fizz_number = 3 - buzz_number = 5 if not type(iterations) == int: raise ValueError("iterations must be defined as integers") From 881d9b3a78523ddb878109e8d707789e27fbfffb Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Sat, 1 Oct 2022 08:42:05 +0000 Subject: [PATCH 11/26] fizzbuzz passing test --- dynamic_programming/fizz_buzz.py | 130 ++++++++++++++++--------------- 1 file changed, 69 insertions(+), 61 deletions(-) diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py index 4c2eefaafa4c..98be1d201b12 100644 --- a/dynamic_programming/fizz_buzz.py +++ b/dynamic_programming/fizz_buzz.py @@ -1,64 +1,72 @@ -#https://en.wikipedia.org/wiki/Fizz_buzz#Programming +# https://en.wikipedia.org/wiki/Fizz_buzz#Programming + + +def fizz_buzz( + number: int, out: str, iterations: int, fizz_number: int, buzz_number: int +) -> None: + """ + Plays FizzBuzz. + Prints Fizz if number is a multiple of 3. + Prints Buzz if its a multiple of 5. + Prints FizzBuzz if its a multiple of both 3 and 5 or 15. + Else Prints The Number Itself. + + >>> fizz_buzz(1,"",7,3,5) + 1 + 2 + Fizz + 4 + Buzz + Fizz + 7 + >>> fizz_buzz(1,"",'a',3,5) + Traceback (most recent call last): + ... + ValueError: iterations must be defined as integers + >>> fizz_buzz(1,"",5,'a',5) + Traceback (most recent call last): + ... + ValueError: fizz_number must be defined as an integer + >>> fizz_buzz(1,"",5,3,'a') + Traceback (most recent call last): + ... + ValueError: buzz_number must be defined as an integer + >>> fizz_buzz(1,"",0,3,5) + Traceback (most recent call last): + ... + ValueError: iterations must be done more than 0 times to play FizzBuzz + >>> fizz_buzz('a',"",5,3,5) + Traceback (most recent call last): + ... + ValueError: starting number must be and integer and be more than 0 + + """ + + if not type(iterations) == int: + raise ValueError("iterations must be defined as integers") + if not type(fizz_number) == int: + raise ValueError("fizz_number must be defined as an integer") + if not type(buzz_number) == int: + raise ValueError("buzz_number must be defined as an integer") + if not iterations >= 1: + raise ValueError("iterations must be done more than 0 times to play FizzBuzz") + if not type(number) == int or not number >= 1: + raise ValueError("starting number must be and integer and be more than 0") + + while number <= iterations: + if number % fizz_number == 0: + out += "Fizz" + if number % buzz_number == 0: + out += "Buzz" + if out == "": + out = str(number) + + print(out) + number += 1 + out = "" -def fizz_buzz(number: int,out: str,iterations: int,fizz_number: int,buzz_number: int) -> None: - """ - Plays FizzBuzz. Prints Fizz if number is a multiple of 3 and Buzz if its a multiple of 5 - Prints FizzBuzz if its a multiple of both 3 and 5 or 15. Else Prints The Number Itself. - - >>> fizz_buzz(1,"",7,3,5) - 1 - 2 - Fizz - 4 - Buzz - Fizz - 7 - >>> fizz_buzz(1,"",'a',3,5) - Traceback (most recent call last): - ... - ValueError: iterations must be defined as integers - >>> fizz_buzz(1,"",5,'a',5) - Traceback (most recent call last): - ... - ValueError: fizz_number must be defined as an integer - >>> fizz_buzz(1,"",5,3,'a') - Traceback (most recent call last): - ... - ValueError: buzz_number must be defined as an integer - >>> fizz_buzz(1,"",0,3,5) - Traceback (most recent call last): - ... - ValueError: iterations must be done more than 0 times to play FizzBuzz - >>> fizz_buzz('a',"",5,3,5) - Traceback (most recent call last): - ... - ValueError: starting number must be and integer and be more than 0 - - """ - - if not type(iterations) == int: - raise ValueError("iterations must be defined as integers") - if not type(fizz_number) == int: - raise ValueError("fizz_number must be defined as an integer") - if not type(buzz_number) == int: - raise ValueError("buzz_number must be defined as an integer") - if not iterations >= 1: - raise ValueError("iterations must be done more than 0 times to play FizzBuzz") - if not type(number) == int or not number >= 1: - raise ValueError("starting number must be and integer and be more than 0") - - while number <= iterations: - if number % fizz_number == 0: - out += "Fizz" - if number % buzz_number == 0: - out += "Buzz" - if out == "": - out = str(number) - - print(out) - number += 1 - out = "" if __name__ == "__main__": - import doctest - doctest.testmod() + import doctest + + doctest.testmod() From ba27d0bee2cfd347c76f90aa791a6fda77798603 Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Sat, 1 Oct 2022 09:14:15 +0000 Subject: [PATCH 12/26] Update dynamic_programming/fizz_buzz.py Co-authored-by: Caeden --- dynamic_programming/fizz_buzz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py index 98be1d201b12..31217c176c3d 100644 --- a/dynamic_programming/fizz_buzz.py +++ b/dynamic_programming/fizz_buzz.py @@ -42,7 +42,7 @@ def fizz_buzz( """ - if not type(iterations) == int: + if not isisinstance(iterations, int): raise ValueError("iterations must be defined as integers") if not type(fizz_number) == int: raise ValueError("fizz_number must be defined as an integer") From c1f17be51b88e2ec8674caa3b3d0ed348c14a037 Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Sat, 1 Oct 2022 09:15:32 +0000 Subject: [PATCH 13/26] Update dynamic_programming/fizz_buzz.py Co-authored-by: Caeden --- dynamic_programming/fizz_buzz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py index 31217c176c3d..9014fff74ca2 100644 --- a/dynamic_programming/fizz_buzz.py +++ b/dynamic_programming/fizz_buzz.py @@ -44,7 +44,7 @@ def fizz_buzz( if not isisinstance(iterations, int): raise ValueError("iterations must be defined as integers") - if not type(fizz_number) == int: + if not isisinstance(fizz_number, int): raise ValueError("fizz_number must be defined as an integer") if not type(buzz_number) == int: raise ValueError("buzz_number must be defined as an integer") From 71928921e2fcfdd9f643d43a5f30b81311eebe8b Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Sat, 1 Oct 2022 09:15:44 +0000 Subject: [PATCH 14/26] Update dynamic_programming/fizz_buzz.py Co-authored-by: Caeden --- dynamic_programming/fizz_buzz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py index 9014fff74ca2..75a73e376415 100644 --- a/dynamic_programming/fizz_buzz.py +++ b/dynamic_programming/fizz_buzz.py @@ -46,7 +46,7 @@ def fizz_buzz( raise ValueError("iterations must be defined as integers") if not isisinstance(fizz_number, int): raise ValueError("fizz_number must be defined as an integer") - if not type(buzz_number) == int: + if not isisinstance(buzz_number, int): raise ValueError("buzz_number must be defined as an integer") if not iterations >= 1: raise ValueError("iterations must be done more than 0 times to play FizzBuzz") From c2534891b97c33439f3421046750626c0e84f1e1 Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Sat, 1 Oct 2022 09:15:53 +0000 Subject: [PATCH 15/26] Update dynamic_programming/fizz_buzz.py Co-authored-by: Caeden --- dynamic_programming/fizz_buzz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py index 75a73e376415..9e845c9d2ebb 100644 --- a/dynamic_programming/fizz_buzz.py +++ b/dynamic_programming/fizz_buzz.py @@ -50,7 +50,7 @@ def fizz_buzz( raise ValueError("buzz_number must be defined as an integer") if not iterations >= 1: raise ValueError("iterations must be done more than 0 times to play FizzBuzz") - if not type(number) == int or not number >= 1: + if not isisinstance(number, int) or not number >= 1: raise ValueError("starting number must be and integer and be more than 0") while number <= iterations: From c5175c49f780471c4734d16d581f33f225e918cc Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Sat, 1 Oct 2022 09:18:12 +0000 Subject: [PATCH 16/26] Update fizz_buzz.py --- dynamic_programming/fizz_buzz.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py index 9e845c9d2ebb..36da3c7c5696 100644 --- a/dynamic_programming/fizz_buzz.py +++ b/dynamic_programming/fizz_buzz.py @@ -3,7 +3,7 @@ def fizz_buzz( number: int, out: str, iterations: int, fizz_number: int, buzz_number: int -) -> None: +) -> str: """ Plays FizzBuzz. Prints Fizz if number is a multiple of 3. @@ -61,7 +61,7 @@ def fizz_buzz( if out == "": out = str(number) - print(out) + return out number += 1 out = "" From bd3e062c15cee27a1bf996b3bba1f92777ba24d5 Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Sat, 1 Oct 2022 09:22:03 +0000 Subject: [PATCH 17/26] Update fizz_buzz.py --- dynamic_programming/fizz_buzz.py | 1 + 1 file changed, 1 insertion(+) diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py index 36da3c7c5696..053d6e2b6a24 100644 --- a/dynamic_programming/fizz_buzz.py +++ b/dynamic_programming/fizz_buzz.py @@ -62,6 +62,7 @@ def fizz_buzz( out = str(number) return out + # print(out) number += 1 out = "" From bd1f05eb6889bb18240056ef777d915364d4dfe2 Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Sat, 1 Oct 2022 10:05:08 +0000 Subject: [PATCH 18/26] Update fizz_buzz.py --- dynamic_programming/fizz_buzz.py | 54 ++++++++++---------------------- 1 file changed, 16 insertions(+), 38 deletions(-) diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py index 053d6e2b6a24..c22747d600a7 100644 --- a/dynamic_programming/fizz_buzz.py +++ b/dynamic_programming/fizz_buzz.py @@ -1,9 +1,7 @@ # https://en.wikipedia.org/wiki/Fizz_buzz#Programming -def fizz_buzz( - number: int, out: str, iterations: int, fizz_number: int, buzz_number: int -) -> str: +def fizz_buzz(number: int, out: str, iterations: int) -> str: """ Plays FizzBuzz. Prints Fizz if number is a multiple of 3. @@ -11,63 +9,43 @@ def fizz_buzz( Prints FizzBuzz if its a multiple of both 3 and 5 or 15. Else Prints The Number Itself. - >>> fizz_buzz(1,"",7,3,5) - 1 - 2 - Fizz - 4 - Buzz - Fizz - 7 - >>> fizz_buzz(1,"",'a',3,5) + >>> fizz_buzz(1,"",7) + '1 2 Fizz 4 Buzz Fizz 7 ' + >>> fizz_buzz(1,"",'a') Traceback (most recent call last): ... ValueError: iterations must be defined as integers - >>> fizz_buzz(1,"",5,'a',5) - Traceback (most recent call last): - ... - ValueError: fizz_number must be defined as an integer - >>> fizz_buzz(1,"",5,3,'a') - Traceback (most recent call last): - ... - ValueError: buzz_number must be defined as an integer - >>> fizz_buzz(1,"",0,3,5) + >>> fizz_buzz(1,"",0) Traceback (most recent call last): ... ValueError: iterations must be done more than 0 times to play FizzBuzz - >>> fizz_buzz('a',"",5,3,5) + >>> fizz_buzz('a',"",5) Traceback (most recent call last): ... ValueError: starting number must be and integer and be more than 0 """ - if not isisinstance(iterations, int): + if not type(iterations) == int: raise ValueError("iterations must be defined as integers") - if not isisinstance(fizz_number, int): - raise ValueError("fizz_number must be defined as an integer") - if not isisinstance(buzz_number, int): - raise ValueError("buzz_number must be defined as an integer") if not iterations >= 1: raise ValueError("iterations must be done more than 0 times to play FizzBuzz") - if not isisinstance(number, int) or not number >= 1: + if not type(number) == int or not number >= 1: raise ValueError("starting number must be and integer and be more than 0") while number <= iterations: - if number % fizz_number == 0: + if number % 3 == 0: out += "Fizz" - if number % buzz_number == 0: + if number % 5 == 0: out += "Buzz" - if out == "": - out = str(number) + if not number % 3 == 0 and not number % 5 == 0: + out += str(number) - return out # print(out) number += 1 - out = "" - - + out += " " + return out if __name__ == "__main__": - import doctest + import doctest - doctest.testmod() + doctest.testmod() From d1a144617a0fa6833a716cd738dba3507a5289c9 Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Sat, 1 Oct 2022 10:54:06 +0000 Subject: [PATCH 19/26] fixed fizzbuzz --- dynamic_programming/fizz_buzz.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py index c22747d600a7..99d51e904c28 100644 --- a/dynamic_programming/fizz_buzz.py +++ b/dynamic_programming/fizz_buzz.py @@ -29,9 +29,15 @@ def fizz_buzz(number: int, out: str, iterations: int) -> str: if not type(iterations) == int: raise ValueError("iterations must be defined as integers") if not iterations >= 1: - raise ValueError("iterations must be done more than 0 times to play FizzBuzz") + raise ValueError( + """iterations must be done more + than 0 times to play FizzBuzz""" + ) if not type(number) == int or not number >= 1: - raise ValueError("starting number must be and integer and be more than 0") + raise ValueError( + """starting number must be + and integer and be more than 0""" + ) while number <= iterations: if number % 3 == 0: @@ -45,7 +51,9 @@ def fizz_buzz(number: int, out: str, iterations: int) -> str: number += 1 out += " " return out + + if __name__ == "__main__": - import doctest + import doctest - doctest.testmod() + doctest.testmod() From 70f4067e62d4b7121423cc9dc542f6d3e44aa331 Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Sat, 1 Oct 2022 11:29:25 +0000 Subject: [PATCH 20/26] Add files via upload --- dynamic_programming/fizz_buzz.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py index 99d51e904c28..f861a8387419 100644 --- a/dynamic_programming/fizz_buzz.py +++ b/dynamic_programming/fizz_buzz.py @@ -18,11 +18,13 @@ def fizz_buzz(number: int, out: str, iterations: int) -> str: >>> fizz_buzz(1,"",0) Traceback (most recent call last): ... - ValueError: iterations must be done more than 0 times to play FizzBuzz + ValueError: iterations must be done more + than 0 times to play FizzBuzz >>> fizz_buzz('a',"",5) Traceback (most recent call last): ... - ValueError: starting number must be and integer and be more than 0 + ValueError: starting number must be + and integer and be more than 0 """ From 4d4daf8bc23bdacd97a199d766de5d165b17dafb Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Sat, 1 Oct 2022 12:39:08 +0000 Subject: [PATCH 21/26] added mechanical energy calculation --- physics/mechanical_energy.py | 67 ++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 physics/mechanical_energy.py diff --git a/physics/mechanical_energy.py b/physics/mechanical_energy.py new file mode 100644 index 000000000000..3755aac03785 --- /dev/null +++ b/physics/mechanical_energy.py @@ -0,0 +1,67 @@ +# https://en.wikipedia.org/wiki/Mechanical_energy + + +def calculate_gravitational_potential_energy( + mass: float, gravity: float, height: float +): + """ + Gravitational Potential Energy Is The Energy + An Object Possesses Due To Its State Of Rest + At A Height. The Kinetic Energy Applied To + Transport a body to that particular state + of rest is converted into potential energy + and stored in the body, hence potential and + kinetic energies are related. + + >>> calculate_gravitational_potential_energy(15,9.8,10) + '1470.0 joules' + >>> calculate_gravitational_potential_energy(1e100,1e100,1e100) + '1e+300 joules' + >>> calculate_gravitational_potential_energy(15.5,9.8,25.5) + '3873.4500000000003 joules' + + """ + unit = "joules" + + try: + gravitational_potential_energy = mass * gravity * height + except Exception: + return -0.0 + gravitational_potential_energy = str(gravitational_potential_energy) + gravitational_potential_energy += " " + unit + return gravitational_potential_energy + + +def calculate_kinetic_energy(mass: float, velocity: float): + """ + + Kinetic Energy is the energy a body possesses due + to its state of motion. The Potential Energy applied + on a body to change its state from motion to rest + converts into kinetic energy, thus kinetic and potential + energies are related. + + >>> calculate_kinetic_energy(10,20) + '2000.0 joules' + >>> calculate_kinetic_energy(10,40) + '8000.0 joules' + >>> calculate_kinetic_energy(4.25,18.9) + '759.0712499999998 joules' + + + """ + unit = "joules" + + try: + kinetic_energy = 0.5 * mass * velocity * velocity + except Exception: + return -0.0 + kinetic_energy = str(kinetic_energy) + kinetic_energy += " " + unit + return kinetic_energy + + +if __name__ == "__main__": + import doctest + + doctest.testmod() From c840af00068b1fdfabef15784d4e4fe75843f4b3 Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Sat, 1 Oct 2022 12:40:08 +0000 Subject: [PATCH 22/26] Delete mechanical_energy.py --- physics/mechanical_energy.py | 67 ------------------------------------ 1 file changed, 67 deletions(-) delete mode 100644 physics/mechanical_energy.py diff --git a/physics/mechanical_energy.py b/physics/mechanical_energy.py deleted file mode 100644 index 3755aac03785..000000000000 --- a/physics/mechanical_energy.py +++ /dev/null @@ -1,67 +0,0 @@ -# https://en.wikipedia.org/wiki/Mechanical_energy - - -def calculate_gravitational_potential_energy( - mass: float, gravity: float, height: float -): - """ - Gravitational Potential Energy Is The Energy - An Object Possesses Due To Its State Of Rest - At A Height. The Kinetic Energy Applied To - Transport a body to that particular state - of rest is converted into potential energy - and stored in the body, hence potential and - kinetic energies are related. - - >>> calculate_gravitational_potential_energy(15,9.8,10) - '1470.0 joules' - >>> calculate_gravitational_potential_energy(1e100,1e100,1e100) - '1e+300 joules' - >>> calculate_gravitational_potential_energy(15.5,9.8,25.5) - '3873.4500000000003 joules' - - """ - unit = "joules" - - try: - gravitational_potential_energy = mass * gravity * height - except Exception: - return -0.0 - gravitational_potential_energy = str(gravitational_potential_energy) - gravitational_potential_energy += " " + unit - return gravitational_potential_energy - - -def calculate_kinetic_energy(mass: float, velocity: float): - """ - - Kinetic Energy is the energy a body possesses due - to its state of motion. The Potential Energy applied - on a body to change its state from motion to rest - converts into kinetic energy, thus kinetic and potential - energies are related. - - >>> calculate_kinetic_energy(10,20) - '2000.0 joules' - >>> calculate_kinetic_energy(10,40) - '8000.0 joules' - >>> calculate_kinetic_energy(4.25,18.9) - '759.0712499999998 joules' - - - """ - unit = "joules" - - try: - kinetic_energy = 0.5 * mass * velocity * velocity - except Exception: - return -0.0 - kinetic_energy = str(kinetic_energy) - kinetic_energy += " " + unit - return kinetic_energy - - -if __name__ == "__main__": - import doctest - - doctest.testmod() From 383b11f08d83400538290e55da82aa1e068c582b Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Sat, 1 Oct 2022 12:46:40 +0000 Subject: [PATCH 23/26] Update fizz_buzz.py --- dynamic_programming/fizz_buzz.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py index f861a8387419..e82feb32569f 100644 --- a/dynamic_programming/fizz_buzz.py +++ b/dynamic_programming/fizz_buzz.py @@ -1,7 +1,7 @@ # https://en.wikipedia.org/wiki/Fizz_buzz#Programming -def fizz_buzz(number: int, out: str, iterations: int) -> str: +def fizz_buzz(number: int, iterations: int) -> str: """ Plays FizzBuzz. Prints Fizz if number is a multiple of 3. @@ -9,18 +9,18 @@ def fizz_buzz(number: int, out: str, iterations: int) -> str: Prints FizzBuzz if its a multiple of both 3 and 5 or 15. Else Prints The Number Itself. - >>> fizz_buzz(1,"",7) + >>> fizz_buzz(1,7) '1 2 Fizz 4 Buzz Fizz 7 ' - >>> fizz_buzz(1,"",'a') + >>> fizz_buzz(1,'a') Traceback (most recent call last): ... ValueError: iterations must be defined as integers - >>> fizz_buzz(1,"",0) + >>> fizz_buzz(1,0) Traceback (most recent call last): ... ValueError: iterations must be done more than 0 times to play FizzBuzz - >>> fizz_buzz('a',"",5) + >>> fizz_buzz('a',5) Traceback (most recent call last): ... ValueError: starting number must be @@ -40,7 +40,7 @@ def fizz_buzz(number: int, out: str, iterations: int) -> str: """starting number must be and integer and be more than 0""" ) - + out = "" while number <= iterations: if number % 3 == 0: out += "Fizz" From 038009e656e076db8834235b6162bff85ec1aa2a Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Mon, 3 Oct 2022 01:37:33 +0000 Subject: [PATCH 24/26] Update dynamic_programming/fizz_buzz.py Co-authored-by: Christian Clauss --- dynamic_programming/fizz_buzz.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py index e82feb32569f..199285c19295 100644 --- a/dynamic_programming/fizz_buzz.py +++ b/dynamic_programming/fizz_buzz.py @@ -32,8 +32,7 @@ def fizz_buzz(number: int, iterations: int) -> str: raise ValueError("iterations must be defined as integers") if not iterations >= 1: raise ValueError( - """iterations must be done more - than 0 times to play FizzBuzz""" + "Iterations must be done more than 0 times to play FizzBuzz" ) if not type(number) == int or not number >= 1: raise ValueError( From 5286c0eafb2661a65426d5982233db1c3cd0226e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 3 Oct 2022 01:38:18 +0000 Subject: [PATCH 25/26] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dynamic_programming/fizz_buzz.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py index 199285c19295..f4270f4736b0 100644 --- a/dynamic_programming/fizz_buzz.py +++ b/dynamic_programming/fizz_buzz.py @@ -31,9 +31,7 @@ def fizz_buzz(number: int, iterations: int) -> str: if not type(iterations) == int: raise ValueError("iterations must be defined as integers") if not iterations >= 1: - raise ValueError( - "Iterations must be done more than 0 times to play FizzBuzz" - ) + raise ValueError("Iterations must be done more than 0 times to play FizzBuzz") if not type(number) == int or not number >= 1: raise ValueError( """starting number must be From 9bf5ea57c35b0cf4fc42bab8aa9e7de772cbb456 Mon Sep 17 00:00:00 2001 From: lostybtw <58177990+lostybtw@users.noreply.github.com> Date: Mon, 3 Oct 2022 10:09:44 +0000 Subject: [PATCH 26/26] Update fizz_buzz.py --- dynamic_programming/fizz_buzz.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/dynamic_programming/fizz_buzz.py b/dynamic_programming/fizz_buzz.py index f4270f4736b0..dd1d21b1075e 100644 --- a/dynamic_programming/fizz_buzz.py +++ b/dynamic_programming/fizz_buzz.py @@ -8,35 +8,42 @@ def fizz_buzz(number: int, iterations: int) -> str: Prints Buzz if its a multiple of 5. Prints FizzBuzz if its a multiple of both 3 and 5 or 15. Else Prints The Number Itself. - >>> fizz_buzz(1,7) '1 2 Fizz 4 Buzz Fizz 7 ' - >>> fizz_buzz(1,'a') - Traceback (most recent call last): - ... - ValueError: iterations must be defined as integers >>> fizz_buzz(1,0) Traceback (most recent call last): ... - ValueError: iterations must be done more - than 0 times to play FizzBuzz - >>> fizz_buzz('a',5) + ValueError: Iterations must be done more than 0 times to play FizzBuzz + >>> fizz_buzz(-5,5) Traceback (most recent call last): - ... + ... ValueError: starting number must be and integer and be more than 0 - + >>> fizz_buzz(10,-5) + Traceback (most recent call last): + ... + ValueError: Iterations must be done more than 0 times to play FizzBuzz + >>> fizz_buzz(1.5,5) + Traceback (most recent call last): + ... + ValueError: starting number must be + and integer and be more than 0 + >>> fizz_buzz(1,5.5) + Traceback (most recent call last): + ... + ValueError: iterations must be defined as integers """ if not type(iterations) == int: raise ValueError("iterations must be defined as integers") - if not iterations >= 1: - raise ValueError("Iterations must be done more than 0 times to play FizzBuzz") if not type(number) == int or not number >= 1: raise ValueError( """starting number must be and integer and be more than 0""" ) + if not iterations >= 1: + raise ValueError("Iterations must be done more than 0 times to play FizzBuzz") + out = "" while number <= iterations: if number % 3 == 0: