From d2bd7676ce87986b60875eaae85ffd04fe245e6d Mon Sep 17 00:00:00 2001 From: Shriyans Gandhi <41372639+shri30yans@users.noreply.github.com> Date: Thu, 28 Oct 2021 20:23:48 +0530 Subject: [PATCH 01/21] Hexagonal number sequence MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A hexagonal number sequence is a sequence of figurate numbers where the nth hexagonal number hₙ is the number of distinct dots in a pattern of dots consisting of the outlines of regular hexagons with sides up to n dots, when the hexagons are overlaid so that they share one vertex. This program returns the hexagonal number sequence of n length. --- maths/series/hexagonalnumbers.py | 98 ++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 maths/series/hexagonalnumbers.py diff --git a/maths/series/hexagonalnumbers.py b/maths/series/hexagonalnumbers.py new file mode 100644 index 000000000000..d7006c519da6 --- /dev/null +++ b/maths/series/hexagonalnumbers.py @@ -0,0 +1,98 @@ +# hexagonalnumbers.py + +""" +A hexagonal number seqeunce is a sequence of figurate numbers +where the nth hexagonal number hₙ is the number of distinct dots +in a pattern of dots consisting of the outlines of regular +hexagons with sides up to n dots, when the hexagons are overlaid +so that they share one vertex. + +1. Calculates the hexagonal numbers sequence with a formula + hₙ = n(2n-1) + where: + hₙ --> is nth element of the sequence + n --> is the number of element in the sequence + reference-->"Hexagonal number" Wikipedia + + +2. Checks if a number is a hexagonal number with a formula + n = (sqrt(8x+1)+1)/4 + where: + x --> is the number to check + n --> is a integer if x is a hexagonal number + + reference-->"Hexagonal number" Wikipedia + +""" + + +class Error(Exception): + """Base class for other exceptions""" + + +class ValueLessThanZero(Error): + """Raised when the input value is less than zero""" + + +class ValueIsZero(Error): + """Raised when the input value is zero""" + + +def len_check(len): + if len < 0: + raise ValueLessThanZero + elif len == 0: + raise ValueIsZero + + +def hexagonal_numbers(len: int): + """ + :param len: max number of elements + :type len: int + :return: Hexagonal numbers as a list + + Tests: + >>> hexagonal_numbers(10) + [0, 1, 6, 15, 28, 45, 66, 91, 120, 153] + >>> hexagonal_numbers(5) + [0, 1, 6, 15, 28] + """ + + len_check(len) + hexagonal_numbers_list = [] + for n in range(len): + num = n * (2 * n - 1) + hexagonal_numbers_list.append(num) + return hexagonal_numbers_list + + +def check_if_hexagonal_number(num: int): + """ + :param num: number to check + :type num: int + :return: boolean + + Tests: + >>> check_if_hexagonal_number(120) + True + >>> check_if_hexagonal_number(5) + False + """ + + n = (((8 * num + 1) ** 1 / 2) + 1) / 4 + isInt = True + try: + int(n) + except ValueError: + isInt = False + return isInt + + +if __name__ == "__main__": + len = 5 + hexagonal_numbers_list = hexagonal_numbers(len) + print(hexagonal_numbers_list) + + num = 120 + check = check_if_hexagonal_number(num) + print(check) From b40553d1fb5a236637a19311055ff452ce206fa6 Mon Sep 17 00:00:00 2001 From: Shriyans Gandhi <41372639+shri30yans@users.noreply.github.com> Date: Fri, 29 Oct 2021 07:42:30 +0530 Subject: [PATCH 02/21] Update hexagonalnumbers.py --- maths/series/hexagonalnumbers.py | 80 +++++++------------------------- 1 file changed, 18 insertions(+), 62 deletions(-) diff --git a/maths/series/hexagonalnumbers.py b/maths/series/hexagonalnumbers.py index d7006c519da6..f5edc364b6a7 100644 --- a/maths/series/hexagonalnumbers.py +++ b/maths/series/hexagonalnumbers.py @@ -1,51 +1,38 @@ # hexagonalnumbers.py """ -A hexagonal number seqeunce is a sequence of figurate numbers +A hexagonal number sequence is a sequence of figurate numbers where the nth hexagonal number hₙ is the number of distinct dots in a pattern of dots consisting of the outlines of regular hexagons with sides up to n dots, when the hexagons are overlaid so that they share one vertex. -1. Calculates the hexagonal numbers sequence with a formula - hₙ = n(2n-1) - where: - hₙ --> is nth element of the sequence - n --> is the number of element in the sequence - reference-->"Hexagonal number" Wikipedia - + Calculates the hexagonal numbers sequence with a formula + hₙ = n(2n-1) + where: + hₙ --> is nth element of the sequence + n --> is the number of element in the sequence + reference-->"Hexagonal number" Wikipedia + -2. Checks if a number is a hexagonal number with a formula - n = (sqrt(8x+1)+1)/4 - where: - x --> is the number to check - n --> is a integer if x is a hexagonal number - - reference-->"Hexagonal number" Wikipedia - """ - -class Error(Exception): - """Base class for other exceptions""" - - -class ValueLessThanZero(Error): +class ValueLessThanZero(Exception): """Raised when the input value is less than zero""" -class ValueIsZero(Error): +class ValueIsZero(Exception): """Raised when the input value is zero""" -def len_check(len): - if len < 0: +def len_check(length:int) -> None: + if length < 0: raise ValueLessThanZero - elif len == 0: + elif length == 0: raise ValueIsZero -def hexagonal_numbers(len: int): +def hexagonal_numbers(length: int) -> list[int]: """ :param len: max number of elements :type len: int @@ -58,41 +45,10 @@ def hexagonal_numbers(len: int): [0, 1, 6, 15, 28] """ - len_check(len) - hexagonal_numbers_list = [] - for n in range(len): - num = n * (2 * n - 1) - hexagonal_numbers_list.append(num) - return hexagonal_numbers_list - - -def check_if_hexagonal_number(num: int): - """ - :param num: number to check - :type num: int - :return: boolean - - Tests: - >>> check_if_hexagonal_number(120) - True - >>> check_if_hexagonal_number(5) - False - """ - - n = (((8 * num + 1) ** 1 / 2) + 1) / 4 - isInt = True - try: - int(n) - except ValueError: - isInt = False - return isInt + len_check(length) + return [n * (2 * n - 1) for n in range(length)] if __name__ == "__main__": - len = 5 - hexagonal_numbers_list = hexagonal_numbers(len) - print(hexagonal_numbers_list) - - num = 120 - check = check_if_hexagonal_number(num) - print(check) + print(hexagonal_numbers(length=10)) + print(hexagonal_numbers(length=10)) From a9bbf96e7d202f7159730d01d0c449fad5bee9ad Mon Sep 17 00:00:00 2001 From: Shriyans Gandhi <41372639+shri30yans@users.noreply.github.com> Date: Fri, 29 Oct 2021 07:49:31 +0530 Subject: [PATCH 03/21] Update hexagonalnumbers.py --- maths/series/hexagonalnumbers.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/maths/series/hexagonalnumbers.py b/maths/series/hexagonalnumbers.py index f5edc364b6a7..082ef93a593a 100644 --- a/maths/series/hexagonalnumbers.py +++ b/maths/series/hexagonalnumbers.py @@ -17,6 +17,7 @@ """ + class ValueLessThanZero(Exception): """Raised when the input value is less than zero""" @@ -25,7 +26,13 @@ class ValueIsZero(Exception): """Raised when the input value is zero""" -def len_check(length:int) -> None: +def len_check(length: int) -> None: + """ + :param length: number to check if it is 0 or less than 0 + :type length: int + :return: None + """ + if length < 0: raise ValueLessThanZero elif length == 0: @@ -50,5 +57,5 @@ def hexagonal_numbers(length: int) -> list[int]: if __name__ == "__main__": - print(hexagonal_numbers(length=10)) + print(hexagonal_numbers(length=5)) print(hexagonal_numbers(length=10)) From 8acb0352dc1283631ac040374802e5a52d8a3e6f Mon Sep 17 00:00:00 2001 From: Shriyans Gandhi <41372639+shri30yans@users.noreply.github.com> Date: Fri, 29 Oct 2021 07:57:59 +0530 Subject: [PATCH 04/21] Update hexagonalnumbers.py --- maths/series/hexagonalnumbers.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/maths/series/hexagonalnumbers.py b/maths/series/hexagonalnumbers.py index 082ef93a593a..3d5d03fa4dec 100644 --- a/maths/series/hexagonalnumbers.py +++ b/maths/series/hexagonalnumbers.py @@ -18,25 +18,24 @@ """ -class ValueLessThanZero(Exception): - """Raised when the input value is less than zero""" - - -class ValueIsZero(Exception): - """Raised when the input value is zero""" - - -def len_check(length: int) -> None: +def length_check(length: int) -> None: """ :param length: number to check if it is 0 or less than 0 :type length: int :return: None + + Tests: + >>> len_check(10) + >>> len_check(0) + ValueError: Length is 0. + >>> len_check(-1) + ValueError: Length is less than 0. """ if length < 0: - raise ValueLessThanZero + raise ValueError("Length is less than 0.") elif length == 0: - raise ValueIsZero + raise ValueError("Length is 0.") def hexagonal_numbers(length: int) -> list[int]: @@ -52,7 +51,7 @@ def hexagonal_numbers(length: int) -> list[int]: [0, 1, 6, 15, 28] """ - len_check(length) + length_check(length) return [n * (2 * n - 1) for n in range(length)] From 56c8f546885731f246687faeb748712056344929 Mon Sep 17 00:00:00 2001 From: Shriyans Gandhi <41372639+shri30yans@users.noreply.github.com> Date: Fri, 29 Oct 2021 11:56:59 +0530 Subject: [PATCH 05/21] Update hexagonalnumbers.py --- maths/series/hexagonalnumbers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/series/hexagonalnumbers.py b/maths/series/hexagonalnumbers.py index 3d5d03fa4dec..001647f1c316 100644 --- a/maths/series/hexagonalnumbers.py +++ b/maths/series/hexagonalnumbers.py @@ -23,7 +23,7 @@ def length_check(length: int) -> None: :param length: number to check if it is 0 or less than 0 :type length: int :return: None - + Tests: >>> len_check(10) >>> len_check(0) From c5c70b0f4e7d08fd09ed3bf895b13d1a7570809a Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 29 Oct 2021 09:28:09 +0200 Subject: [PATCH 06/21] Update and rename hexagonalnumbers.py to hexagonal_numbers.py --- ...xagonalnumbers.py => hexagonal_numbers.py} | 26 ++----------------- 1 file changed, 2 insertions(+), 24 deletions(-) rename maths/series/{hexagonalnumbers.py => hexagonal_numbers.py} (66%) diff --git a/maths/series/hexagonalnumbers.py b/maths/series/hexagonal_numbers.py similarity index 66% rename from maths/series/hexagonalnumbers.py rename to maths/series/hexagonal_numbers.py index 001647f1c316..3d09ce263684 100644 --- a/maths/series/hexagonalnumbers.py +++ b/maths/series/hexagonal_numbers.py @@ -1,5 +1,3 @@ -# hexagonalnumbers.py - """ A hexagonal number sequence is a sequence of figurate numbers where the nth hexagonal number hₙ is the number of distinct dots @@ -14,30 +12,9 @@ n --> is the number of element in the sequence reference-->"Hexagonal number" Wikipedia - """ -def length_check(length: int) -> None: - """ - :param length: number to check if it is 0 or less than 0 - :type length: int - :return: None - - Tests: - >>> len_check(10) - >>> len_check(0) - ValueError: Length is 0. - >>> len_check(-1) - ValueError: Length is less than 0. - """ - - if length < 0: - raise ValueError("Length is less than 0.") - elif length == 0: - raise ValueError("Length is 0.") - - def hexagonal_numbers(length: int) -> list[int]: """ :param len: max number of elements @@ -51,7 +28,8 @@ def hexagonal_numbers(length: int) -> list[int]: [0, 1, 6, 15, 28] """ - length_check(length) + if length <= 0: + raise ValueError("Length must be a positive number.") return [n * (2 * n - 1) for n in range(length)] From 0212ecc70be14ccca82f6b353fcd6aaae2ca3443 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 29 Oct 2021 09:36:17 +0200 Subject: [PATCH 07/21] Length must be a positive integer --- maths/series/hexagonal_numbers.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/maths/series/hexagonal_numbers.py b/maths/series/hexagonal_numbers.py index 3d09ce263684..582b1989b7c6 100644 --- a/maths/series/hexagonal_numbers.py +++ b/maths/series/hexagonal_numbers.py @@ -26,10 +26,14 @@ def hexagonal_numbers(length: int) -> list[int]: [0, 1, 6, 15, 28, 45, 66, 91, 120, 153] >>> hexagonal_numbers(5) [0, 1, 6, 15, 28] + >>> hexagonal_numbers(0) + Traceback (most recent call last): + ... + ValueError: Length must be a positive integer. """ - if length <= 0: - raise ValueError("Length must be a positive number.") + if length <= 0 or not isinstance(length, int): + raise ValueError("Length must be a positive integer.") return [n * (2 * n - 1) for n in range(length)] From 6a39c104ca2072bdc41b88c3a03b64b8c92bce96 Mon Sep 17 00:00:00 2001 From: Shriyans Gandhi <41372639+shri30yans@users.noreply.github.com> Date: Mon, 3 Oct 2022 15:56:59 +0530 Subject: [PATCH 08/21] Create dodecahedron.py --- maths/dodecahedron.py | 75 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 maths/dodecahedron.py diff --git a/maths/dodecahedron.py b/maths/dodecahedron.py new file mode 100644 index 000000000000..eaa0e8115c5a --- /dev/null +++ b/maths/dodecahedron.py @@ -0,0 +1,75 @@ +# dodecahedron.py + +""" +A regular dodecahedron is a three-dimensional figure made up of 12 pentagon faces having the same equal size. +""" + +def dodecahedron_surface_area(edge: float) -> float: + """ + Calculates the surface area of a regular dodecahedron + a = 3 * ((25 + 10 * (5** (1 / 2))) ** (1 / 2 )) * (e**2) + where: + a --> is the area of the dodecahedron + e --> is the length of the edge + reference-->"Dodecahedron" Study.com + + + :param edge: length of the edge of the dodecahedron + :type edge: float + :return: the surface area of the dodecahedron as a float + + + Tests: + >>> dodecahedron_surface_area(5) + 516.1432201766901 + >>> dodecahedron_surface_area(5) + 2064.5728807067603 + >>> dodecahedron_surface_area(0) + Traceback (most recent call last): + ... + ValueError: Length must be a positive integer. + """ + + if edge <= 0 or not isinstance(edge, int): + raise ValueError("Length must be a positive.") + surface_area = 3 * ((25 + 10 * (5 ** (1 / 2))) ** (1 / 2)) * (edge**2) + return surface_area + + +def dodecahedron_volume(edge: float) -> float: + """ + Calculates the volume of a regular dodecahedron + v = ((15 + (7 * (5** (1 / 2)))) / 4) * (e**3) + where: + v --> is the volume of the dodecahedron + e --> is the length of the edge + reference-->"Dodecahedron" Study.com + + + :param edge: length of the edge of the dodecahedron + :type edge: float + :return: the volume of the dodecahedron as a float + + Tests: + >>> dodecahedron_volume(5) + 957.8898700780791 + >>> dodecahedron_volume(10) + 7663.118960624633 + >>> dodecahedron_volume(0) + Traceback (most recent call last): + ... + ValueError: Length must be a positive integer. + """ + + if edge <= 0 or not isinstance(edge, int): + raise ValueError("Length must be a positive.") + + volume = ((15 + (7 * (5 ** (1 / 2)))) / 4) * (edge**3) + return volume + + +if __name__ == "__main__": + edge = 0 + print("Dodecahedron edge:", edge) + print("Surface area: ", dodecahedron_surface_area(edge=edge)) + print("Volume: ", dodecahedron_volume(edge=edge)) From bc9f6d91e0ba99fb87d23146834bfc563debe10b Mon Sep 17 00:00:00 2001 From: Shriyans Gandhi <41372639+shri30yans@users.noreply.github.com> Date: Mon, 3 Oct 2022 16:02:34 +0530 Subject: [PATCH 09/21] Update dodecahedron.py --- maths/dodecahedron.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/maths/dodecahedron.py b/maths/dodecahedron.py index eaa0e8115c5a..1b634f1294e1 100644 --- a/maths/dodecahedron.py +++ b/maths/dodecahedron.py @@ -11,8 +11,8 @@ def dodecahedron_surface_area(edge: float) -> float: where: a --> is the area of the dodecahedron e --> is the length of the edge - reference-->"Dodecahedron" Study.com - + reference-->"Dodecahedron" Wikipedia + :param edge: length of the edge of the dodecahedron :type edge: float @@ -43,8 +43,8 @@ def dodecahedron_volume(edge: float) -> float: where: v --> is the volume of the dodecahedron e --> is the length of the edge - reference-->"Dodecahedron" Study.com - + reference-->"Dodecahedron" Wikipedia + :param edge: length of the edge of the dodecahedron :type edge: float From ca2a742978c1382a98904becb1b8d900230ef2e1 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 10:42:20 +0000 Subject: [PATCH 10/21] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/dodecahedron.py | 1 + 1 file changed, 1 insertion(+) diff --git a/maths/dodecahedron.py b/maths/dodecahedron.py index 1b634f1294e1..fe6d14b32eea 100644 --- a/maths/dodecahedron.py +++ b/maths/dodecahedron.py @@ -4,6 +4,7 @@ A regular dodecahedron is a three-dimensional figure made up of 12 pentagon faces having the same equal size. """ + def dodecahedron_surface_area(edge: float) -> float: """ Calculates the surface area of a regular dodecahedron From 24c835a9f5123478cf4e0052ba9fccfa4b21104a Mon Sep 17 00:00:00 2001 From: Shriyans Gandhi <41372639+shri30yans@users.noreply.github.com> Date: Mon, 3 Oct 2022 16:14:33 +0530 Subject: [PATCH 11/21] Update dodecahedron.py --- maths/dodecahedron.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/maths/dodecahedron.py b/maths/dodecahedron.py index fe6d14b32eea..3749ed5a8dd9 100644 --- a/maths/dodecahedron.py +++ b/maths/dodecahedron.py @@ -1,10 +1,9 @@ -# dodecahedron.py +# hexagonalnumbers.py """ A regular dodecahedron is a three-dimensional figure made up of 12 pentagon faces having the same equal size. """ - def dodecahedron_surface_area(edge: float) -> float: """ Calculates the surface area of a regular dodecahedron @@ -12,8 +11,8 @@ def dodecahedron_surface_area(edge: float) -> float: where: a --> is the area of the dodecahedron e --> is the length of the edge - reference-->"Dodecahedron" Wikipedia - + reference-->"Dodecahedron" Study.com + :param edge: length of the edge of the dodecahedron :type edge: float @@ -28,7 +27,7 @@ def dodecahedron_surface_area(edge: float) -> float: >>> dodecahedron_surface_area(0) Traceback (most recent call last): ... - ValueError: Length must be a positive integer. + ValueError: Length must be a positive. """ if edge <= 0 or not isinstance(edge, int): @@ -44,8 +43,8 @@ def dodecahedron_volume(edge: float) -> float: where: v --> is the volume of the dodecahedron e --> is the length of the edge - reference-->"Dodecahedron" Wikipedia - + reference-->"Dodecahedron" Study.com + :param edge: length of the edge of the dodecahedron :type edge: float @@ -59,7 +58,7 @@ def dodecahedron_volume(edge: float) -> float: >>> dodecahedron_volume(0) Traceback (most recent call last): ... - ValueError: Length must be a positive integer. + ValueError: Length must be a positive. """ if edge <= 0 or not isinstance(edge, int): From 8fe2b08dba497e5d659bf5971063eba8f9668af7 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 10:45:29 +0000 Subject: [PATCH 12/21] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/dodecahedron.py | 1 + 1 file changed, 1 insertion(+) diff --git a/maths/dodecahedron.py b/maths/dodecahedron.py index 3749ed5a8dd9..788708982f34 100644 --- a/maths/dodecahedron.py +++ b/maths/dodecahedron.py @@ -4,6 +4,7 @@ A regular dodecahedron is a three-dimensional figure made up of 12 pentagon faces having the same equal size. """ + def dodecahedron_surface_area(edge: float) -> float: """ Calculates the surface area of a regular dodecahedron From 5114808de3f0838f9850bfb4bd4d7e1a6db52b90 Mon Sep 17 00:00:00 2001 From: Shriyans Gandhi <41372639+shri30yans@users.noreply.github.com> Date: Mon, 3 Oct 2022 16:18:54 +0530 Subject: [PATCH 13/21] Update dodecahedron.py --- maths/dodecahedron.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/maths/dodecahedron.py b/maths/dodecahedron.py index 788708982f34..eaf7103ce5cb 100644 --- a/maths/dodecahedron.py +++ b/maths/dodecahedron.py @@ -28,11 +28,11 @@ def dodecahedron_surface_area(edge: float) -> float: >>> dodecahedron_surface_area(0) Traceback (most recent call last): ... - ValueError: Length must be a positive. + ValueError: Length must be positive. """ if edge <= 0 or not isinstance(edge, int): - raise ValueError("Length must be a positive.") + raise ValueError("Length must be positive.") surface_area = 3 * ((25 + 10 * (5 ** (1 / 2))) ** (1 / 2)) * (edge**2) return surface_area @@ -59,11 +59,11 @@ def dodecahedron_volume(edge: float) -> float: >>> dodecahedron_volume(0) Traceback (most recent call last): ... - ValueError: Length must be a positive. + ValueError: Length must be positive. """ if edge <= 0 or not isinstance(edge, int): - raise ValueError("Length must be a positive.") + raise ValueError("Length must be positive.") volume = ((15 + (7 * (5 ** (1 / 2)))) / 4) * (edge**3) return volume From adab1733169d1be5289bc18648c86ab993c605ca Mon Sep 17 00:00:00 2001 From: Shriyans Gandhi <41372639+shri30yans@users.noreply.github.com> Date: Mon, 3 Oct 2022 16:24:22 +0530 Subject: [PATCH 14/21] Update dodecahedron.py --- maths/dodecahedron.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/maths/dodecahedron.py b/maths/dodecahedron.py index eaf7103ce5cb..a7673eb29b91 100644 --- a/maths/dodecahedron.py +++ b/maths/dodecahedron.py @@ -1,7 +1,8 @@ -# hexagonalnumbers.py +## dodecahedron.py """ -A regular dodecahedron is a three-dimensional figure made up of 12 pentagon faces having the same equal size. +A regular dodecahedron is a three-dimensional figure made up of +12 pentagon faces having the same equal size. """ @@ -28,11 +29,11 @@ def dodecahedron_surface_area(edge: float) -> float: >>> dodecahedron_surface_area(0) Traceback (most recent call last): ... - ValueError: Length must be positive. + ValueError: Length must be a positive. """ if edge <= 0 or not isinstance(edge, int): - raise ValueError("Length must be positive.") + raise ValueError("Length must be a positive.") surface_area = 3 * ((25 + 10 * (5 ** (1 / 2))) ** (1 / 2)) * (edge**2) return surface_area @@ -59,11 +60,11 @@ def dodecahedron_volume(edge: float) -> float: >>> dodecahedron_volume(0) Traceback (most recent call last): ... - ValueError: Length must be positive. + ValueError: Length must be a positive. """ if edge <= 0 or not isinstance(edge, int): - raise ValueError("Length must be positive.") + raise ValueError("Length must be a positive.") volume = ((15 + (7 * (5 ** (1 / 2)))) / 4) * (edge**3) return volume From 34ad557661cd1cafbee5d185d00d21dc817e88e2 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 10:56:24 +0000 Subject: [PATCH 15/21] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/dodecahedron.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/dodecahedron.py b/maths/dodecahedron.py index a7673eb29b91..1c72d3c6e0a5 100644 --- a/maths/dodecahedron.py +++ b/maths/dodecahedron.py @@ -1,7 +1,7 @@ ## dodecahedron.py """ -A regular dodecahedron is a three-dimensional figure made up of +A regular dodecahedron is a three-dimensional figure made up of 12 pentagon faces having the same equal size. """ From aaf951509bf72e38d2da903c5eb6b394a51efaac Mon Sep 17 00:00:00 2001 From: Shriyans Gandhi <41372639+shri30yans@users.noreply.github.com> Date: Mon, 3 Oct 2022 16:33:09 +0530 Subject: [PATCH 16/21] Update dodecahedron.py --- maths/dodecahedron.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maths/dodecahedron.py b/maths/dodecahedron.py index 1c72d3c6e0a5..b8eae710531d 100644 --- a/maths/dodecahedron.py +++ b/maths/dodecahedron.py @@ -1,4 +1,4 @@ -## dodecahedron.py +# dodecahedron.py """ A regular dodecahedron is a three-dimensional figure made up of @@ -71,7 +71,7 @@ def dodecahedron_volume(edge: float) -> float: if __name__ == "__main__": - edge = 0 + edge = 5 print("Dodecahedron edge:", edge) print("Surface area: ", dodecahedron_surface_area(edge=edge)) print("Volume: ", dodecahedron_volume(edge=edge)) From 8f1850f97f0f4e414e0f3b4469a5c6e644bf73d6 Mon Sep 17 00:00:00 2001 From: Shriyans Gandhi <41372639+shri30yans@users.noreply.github.com> Date: Mon, 3 Oct 2022 16:37:42 +0530 Subject: [PATCH 17/21] Update dodecahedron.py --- maths/dodecahedron.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/maths/dodecahedron.py b/maths/dodecahedron.py index b8eae710531d..b3766d900166 100644 --- a/maths/dodecahedron.py +++ b/maths/dodecahedron.py @@ -24,9 +24,9 @@ def dodecahedron_surface_area(edge: float) -> float: Tests: >>> dodecahedron_surface_area(5) 516.1432201766901 - >>> dodecahedron_surface_area(5) + >>> dodecahedron_surface_area(10) 2064.5728807067603 - >>> dodecahedron_surface_area(0) + >>> dodecahedron_surface_area(-1) Traceback (most recent call last): ... ValueError: Length must be a positive. @@ -57,7 +57,7 @@ def dodecahedron_volume(edge: float) -> float: 957.8898700780791 >>> dodecahedron_volume(10) 7663.118960624633 - >>> dodecahedron_volume(0) + >>> dodecahedron_volume(-1) Traceback (most recent call last): ... ValueError: Length must be a positive. From b14eb4cc99ee9264c02bfbbbf4ba8d560963d3d3 Mon Sep 17 00:00:00 2001 From: Shriyans Gandhi <41372639+shri30yans@users.noreply.github.com> Date: Tue, 18 Oct 2022 17:04:39 +0530 Subject: [PATCH 18/21] Apply suggestions from code review Co-authored-by: Paul <56065602+ZeroDayOwl@users.noreply.github.com> --- maths/dodecahedron.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/maths/dodecahedron.py b/maths/dodecahedron.py index b3766d900166..1dd289fae895 100644 --- a/maths/dodecahedron.py +++ b/maths/dodecahedron.py @@ -71,7 +71,5 @@ def dodecahedron_volume(edge: float) -> float: if __name__ == "__main__": - edge = 5 - print("Dodecahedron edge:", edge) - print("Surface area: ", dodecahedron_surface_area(edge=edge)) - print("Volume: ", dodecahedron_volume(edge=edge)) + import doctest + doctest.testmod() From aaa6f993d14ba0ad6911ab47029eb6f88f064c35 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 18 Oct 2022 11:36:05 +0000 Subject: [PATCH 19/21] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/dodecahedron.py | 1 + 1 file changed, 1 insertion(+) diff --git a/maths/dodecahedron.py b/maths/dodecahedron.py index 1dd289fae895..fa5591fce35b 100644 --- a/maths/dodecahedron.py +++ b/maths/dodecahedron.py @@ -72,4 +72,5 @@ def dodecahedron_volume(edge: float) -> float: if __name__ == "__main__": import doctest + doctest.testmod() From 4e7f59021c0f60a71680cb3a2fc18b1ef656e244 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 31 Oct 2022 18:14:41 +0100 Subject: [PATCH 20/21] Apply suggestions from code review --- maths/dodecahedron.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/maths/dodecahedron.py b/maths/dodecahedron.py index fa5591fce35b..095c18bb4c38 100644 --- a/maths/dodecahedron.py +++ b/maths/dodecahedron.py @@ -34,8 +34,7 @@ def dodecahedron_surface_area(edge: float) -> float: if edge <= 0 or not isinstance(edge, int): raise ValueError("Length must be a positive.") - surface_area = 3 * ((25 + 10 * (5 ** (1 / 2))) ** (1 / 2)) * (edge**2) - return surface_area + return 3 * ((25 + 10 * (5 ** (1 / 2))) ** (1 / 2)) * (edge**2) def dodecahedron_volume(edge: float) -> float: @@ -66,8 +65,7 @@ def dodecahedron_volume(edge: float) -> float: if edge <= 0 or not isinstance(edge, int): raise ValueError("Length must be a positive.") - volume = ((15 + (7 * (5 ** (1 / 2)))) / 4) * (edge**3) - return volume + return ((15 + (7 * (5 ** (1 / 2)))) / 4) * (edge**3) if __name__ == "__main__": From ff4477f8fed30e7e429f6980cada6725471f08da Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 31 Oct 2022 18:15:22 +0100 Subject: [PATCH 21/21] Update dodecahedron.py --- maths/dodecahedron.py | 1 - 1 file changed, 1 deletion(-) diff --git a/maths/dodecahedron.py b/maths/dodecahedron.py index 095c18bb4c38..856245f4a868 100644 --- a/maths/dodecahedron.py +++ b/maths/dodecahedron.py @@ -64,7 +64,6 @@ def dodecahedron_volume(edge: float) -> float: if edge <= 0 or not isinstance(edge, int): raise ValueError("Length must be a positive.") - return ((15 + (7 * (5 ** (1 / 2)))) / 4) * (edge**3)