From f52b33b2154e0866753068aa0ffc364071fa11b5 Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Thu, 9 Jan 2025 16:46:16 +0200 Subject: [PATCH 01/32] Update and rename __init__.py to FindPrimeNumbers.py --- solutions/FindPrimeNumbers.py | 51 +++++++++++++++++++++++++++++++++++ solutions/__init__.py | 1 - 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 solutions/FindPrimeNumbers.py delete mode 100644 solutions/__init__.py diff --git a/solutions/FindPrimeNumbers.py b/solutions/FindPrimeNumbers.py new file mode 100644 index 000000000..0f8561523 --- /dev/null +++ b/solutions/FindPrimeNumbers.py @@ -0,0 +1,51 @@ +"""" +## Challenge Overview +Identify all prime numbers up to a given integer \( N \). A prime number is greater than 1 and only divisible by 1 and itself. + + Steps to Solve +1. Understand Prime Numbers: + - Prime numbers: 2, 3, 5, 7, 11, etc. + +2. Input: + - Single integer \( N \), e.g., \( N = 20 \). + +3. **Output**: + - List of primes up to \( N \), e.g., [2, 3, 5, 7, 11, 13, 17, 19]. + +### Implementation +1. Iterate Through Numbers: + - Loop from 2 to \( N \). + +2. Check if Each Number is Prime: + - Function to check if a number is prime: + - Return False if < 2. + - Check divisibility from 2 to sqrt(number). + - Return True if no divisors found. + +3. Collect Prime Numbers: + - Use the function to collect primes up to \( N \). + +---------------------------------------------------------------------------------------------------------------------------------------- +"""" + + +def is_prime(n): + """Check if a number is prime.""" + if n <= 1: + return False + for i in range(2, int(n**0.5) + 1): + if n % i == 0: + return False + return True + +def find_primes_up_to_n(n): + """Find all prime numbers up to n.""" + primes = [] + for num in range(2, n + 1): + if is_prime(num): + primes.append(num) + return primes + +# Example usage +N = 20 +print("Prime numbers up to", N, ":", find_primes_up_to_n(N)) diff --git a/solutions/__init__.py b/solutions/__init__.py deleted file mode 100644 index 8b1378917..000000000 --- a/solutions/__init__.py +++ /dev/null @@ -1 +0,0 @@ - From 4bbc2cb0406275ffd2cd98a799fd845f9b6c2a9b Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Thu, 9 Jan 2025 17:34:32 +0200 Subject: [PATCH 02/32] Update README.md --- solutions/README.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/solutions/README.md b/solutions/README.md index 9852346d2..1416287d8 100644 --- a/solutions/README.md +++ b/solutions/README.md @@ -1 +1,26 @@ -# Solutions +# Find All Prime Numbers Up to N +## Challenge Overview +Identify all prime numbers up to a given integer \( N \). A prime number is greater than 1 and only divisible by 1 and itself. + +### Steps to Solve +1. **Understand Prime Numbers**: + - Prime numbers: 2, 3, 5, 7, 11, etc. + +2. **Input**: + - Single integer \( N \), e.g., \( N = 20 \). + +3. **Output**: + - List of primes up to \( N \), e.g., [2, 3, 5, 7, 11, 13, 17, 19]. + +### Implementation +1. **Iterate Through Numbers**: + - Loop from 2 to \( N \). + +2. **Check if Each Number is Prime**: + - Function to check if a number is prime: + - Return False if < 2. + - Check divisibility from 2 to sqrt(number). + - Return True if no divisors found. + +3. **Collect Prime Numbers**: + - Use the function to collect primes up to \( N \). From 3c409cd073aa20f180fa9802dcf2d78a197ba7bd Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Thu, 9 Jan 2025 17:46:47 +0200 Subject: [PATCH 03/32] Update README.md --- solutions/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/solutions/README.md b/solutions/README.md index 1416287d8..6f0c2ca78 100644 --- a/solutions/README.md +++ b/solutions/README.md @@ -1,4 +1,5 @@ # Find All Prime Numbers Up to N + ## Challenge Overview Identify all prime numbers up to a given integer \( N \). A prime number is greater than 1 and only divisible by 1 and itself. @@ -24,3 +25,4 @@ Identify all prime numbers up to a given integer \( N \). A prime number is grea 3. **Collect Prime Numbers**: - Use the function to collect primes up to \( N \). + From 0f0ea4065b9f497da7c2dc4b06159e55cb64d8f4 Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Thu, 9 Jan 2025 17:54:35 +0200 Subject: [PATCH 04/32] Create ci.yml --- solutions/github/workflows/ci.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 solutions/github/workflows/ci.yml diff --git a/solutions/github/workflows/ci.yml b/solutions/github/workflows/ci.yml new file mode 100644 index 000000000..c5eb74b56 --- /dev/null +++ b/solutions/github/workflows/ci.yml @@ -0,0 +1,30 @@ +name: CI + +on: [push, pull_request] + +jobs: + lint-and-format: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' # Specify the Python version you need + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install black pylint markdownlint-cli + + - name: Format code with black + run: black your_script.py + + - name: Lint code with pylint + run: pylint your_script.py + + - name: Check markdown formatting + run: markdownlint **/*.md From adf66e98ac84c0e7300eb6fa3874d3d50eee1e75 Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Thu, 9 Jan 2025 18:01:30 +0200 Subject: [PATCH 05/32] Update FindPrimeNumbers.py --- solutions/FindPrimeNumbers.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/solutions/FindPrimeNumbers.py b/solutions/FindPrimeNumbers.py index 0f8561523..16a3a4010 100644 --- a/solutions/FindPrimeNumbers.py +++ b/solutions/FindPrimeNumbers.py @@ -12,18 +12,6 @@ 3. **Output**: - List of primes up to \( N \), e.g., [2, 3, 5, 7, 11, 13, 17, 19]. -### Implementation -1. Iterate Through Numbers: - - Loop from 2 to \( N \). - -2. Check if Each Number is Prime: - - Function to check if a number is prime: - - Return False if < 2. - - Check divisibility from 2 to sqrt(number). - - Return True if no divisors found. - -3. Collect Prime Numbers: - - Use the function to collect primes up to \( N \). ---------------------------------------------------------------------------------------------------------------------------------------- """" From 5e0c9ca79ab1b2a1ce2b7a8cba8dac06a8d8a661 Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Thu, 9 Jan 2025 18:03:04 +0200 Subject: [PATCH 06/32] Update FindPrimeNumbers.py --- solutions/FindPrimeNumbers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/solutions/FindPrimeNumbers.py b/solutions/FindPrimeNumbers.py index 16a3a4010..bb2827057 100644 --- a/solutions/FindPrimeNumbers.py +++ b/solutions/FindPrimeNumbers.py @@ -12,7 +12,8 @@ 3. **Output**: - List of primes up to \( N \), e.g., [2, 3, 5, 7, 11, 13, 17, 19]. - + Created on: 09/01/25 +@author: Zeinab Shadabshoar ---------------------------------------------------------------------------------------------------------------------------------------- """" From ddd6b85d204fc7a88ecd1fb9ebd2e37cba7db9af Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Thu, 9 Jan 2025 18:17:31 +0200 Subject: [PATCH 07/32] Update FindPrimeNumbers.py --- solutions/FindPrimeNumbers.py | 53 +++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/solutions/FindPrimeNumbers.py b/solutions/FindPrimeNumbers.py index bb2827057..df9d90de2 100644 --- a/solutions/FindPrimeNumbers.py +++ b/solutions/FindPrimeNumbers.py @@ -1,25 +1,30 @@ -"""" -## Challenge Overview -Identify all prime numbers up to a given integer \( N \). A prime number is greater than 1 and only divisible by 1 and itself. +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +This module defines the function `find_primes_up_to_n` to identify all prime numbers +up to a given integer \( N \). A prime number is greater than 1 and divisible only by 1 and itself. - Steps to Solve -1. Understand Prime Numbers: - - Prime numbers: 2, 3, 5, 7, 11, etc. +Author: Zeinab Shadabshoar +Date: 09 01 2025 +""" -2. Input: - - Single integer \( N \), e.g., \( N = 20 \). -3. **Output**: - - List of primes up to \( N \), e.g., [2, 3, 5, 7, 11, 13, 17, 19]. +def is_prime(n: int) -> bool: + """ + Checks if a given number is prime. - Created on: 09/01/25 -@author: Zeinab Shadabshoar ----------------------------------------------------------------------------------------------------------------------------------------- -"""" + Parameters: + n (int): The number to check. + Returns: + bool: True if the number is prime, False otherwise. -def is_prime(n): - """Check if a number is prime.""" + Examples: + >>> is_prime(2) + True + >>> is_prime(4) + False + """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): @@ -27,8 +32,20 @@ def is_prime(n): return False return True -def find_primes_up_to_n(n): - """Find all prime numbers up to n.""" +def find_primes_up_to_n(n: int) -> list: + """ + Finds all prime numbers up to the given number \( N \). + + Parameters: + n (int): The upper limit to find primes up to. + + Returns: + list: A list of all prime numbers up to \( N \). + + Examples: + >>> find_primes_up_to_n(20) + [2, 3, 5, 7, 11, 13, 17, 19] + """ primes = [] for num in range(2, n + 1): if is_prime(num): From 185edf5779dec5747579327cd3d5ded62776486e Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Thu, 9 Jan 2025 18:29:28 +0200 Subject: [PATCH 08/32] Update README.md --- solutions/README.md | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/solutions/README.md b/solutions/README.md index 6f0c2ca78..139597f9c 100644 --- a/solutions/README.md +++ b/solutions/README.md @@ -1,28 +1,2 @@ -# Find All Prime Numbers Up to N -## Challenge Overview -Identify all prime numbers up to a given integer \( N \). A prime number is greater than 1 and only divisible by 1 and itself. - -### Steps to Solve -1. **Understand Prime Numbers**: - - Prime numbers: 2, 3, 5, 7, 11, etc. - -2. **Input**: - - Single integer \( N \), e.g., \( N = 20 \). - -3. **Output**: - - List of primes up to \( N \), e.g., [2, 3, 5, 7, 11, 13, 17, 19]. - -### Implementation -1. **Iterate Through Numbers**: - - Loop from 2 to \( N \). - -2. **Check if Each Number is Prime**: - - Function to check if a number is prime: - - Return False if < 2. - - Check divisibility from 2 to sqrt(number). - - Return True if no divisors found. - -3. **Collect Prime Numbers**: - - Use the function to collect primes up to \( N \). From 9ddf90e09261ba2321d36d6469502ae7a1cf86eb Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Thu, 9 Jan 2025 18:42:29 +0200 Subject: [PATCH 09/32] Update README.md --- solutions/README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/solutions/README.md b/solutions/README.md index 139597f9c..a4a814fae 100644 --- a/solutions/README.md +++ b/solutions/README.md @@ -1,2 +1,29 @@ +# Find All Prime Numbers Up to N + +## Challenge Overview +Identify all prime numbers up to a given integer \( N \). A prime number is greater than 1 and only divisible by 1 and itself. + +### Steps to Solve +1. **Understand Prime Numbers**: + - Prime numbers: 2, 3, 5, 7, 11, etc. + +2. **Input**: + - Single integer \( N \), e.g., \( N = 20 \). + +3. **Output**: + - List of primes up to \( N \), e.g., [2, 3, 5, 7, 11, 13, 17, 19]. + +### Implementation +1. **Iterate Through Numbers**: + - Loop from 2 to \( N \). + +2. **Check if Each Number is Prime**: + - Function to check if a number is prime: + - Return False if < 2. + - Check divisibility from 2 to sqrt(number). + - Return True if no divisors found. + +3. **Collect Prime Numbers**: + - Use the function to collect primes up to \( N \). From 8f8a667ca1310e9a8061b48ef06363c4c34b2cb6 Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Thu, 9 Jan 2025 18:49:13 +0200 Subject: [PATCH 10/32] Update README.md --- solutions/README.md | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/solutions/README.md b/solutions/README.md index a4a814fae..9e40ea356 100644 --- a/solutions/README.md +++ b/solutions/README.md @@ -1,29 +1,3 @@ -# Find All Prime Numbers Up to N - -## Challenge Overview -Identify all prime numbers up to a given integer \( N \). A prime number is greater than 1 and only divisible by 1 and itself. - -### Steps to Solve -1. **Understand Prime Numbers**: - - Prime numbers: 2, 3, 5, 7, 11, etc. - -2. **Input**: - - Single integer \( N \), e.g., \( N = 20 \). - -3. **Output**: - - List of primes up to \( N \), e.g., [2, 3, 5, 7, 11, 13, 17, 19]. - -### Implementation -1. **Iterate Through Numbers**: - - Loop from 2 to \( N \). - -2. **Check if Each Number is Prime**: - - Function to check if a number is prime: - - Return False if < 2. - - Check divisibility from 2 to sqrt(number). - - Return True if no divisors found. - -3. **Collect Prime Numbers**: - - Use the function to collect primes up to \( N \). +# Solutions From fb4bb4b8b493d84ec1b5b5566275ee853ed5628f Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Thu, 9 Jan 2025 20:31:58 +0200 Subject: [PATCH 11/32] Update README.md --- solutions/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/solutions/README.md b/solutions/README.md index 9e40ea356..9852346d2 100644 --- a/solutions/README.md +++ b/solutions/README.md @@ -1,3 +1 @@ # Solutions - - From f723c109202c81ae63082d461dee700e7861c56c Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Thu, 9 Jan 2025 22:39:02 +0200 Subject: [PATCH 12/32] Update and rename FindPrimeNumbers.py to Find-Prime-Numbers.py --- solutions/{FindPrimeNumbers.py => Find-Prime-Numbers.py} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename solutions/{FindPrimeNumbers.py => Find-Prime-Numbers.py} (98%) diff --git a/solutions/FindPrimeNumbers.py b/solutions/Find-Prime-Numbers.py similarity index 98% rename from solutions/FindPrimeNumbers.py rename to solutions/Find-Prime-Numbers.py index df9d90de2..6c9207607 100644 --- a/solutions/FindPrimeNumbers.py +++ b/solutions/Find-Prime-Numbers.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -""" +r""" This module defines the function `find_primes_up_to_n` to identify all prime numbers up to a given integer \( N \). A prime number is greater than 1 and divisible only by 1 and itself. @@ -10,7 +10,7 @@ def is_prime(n: int) -> bool: - """ + r""" Checks if a given number is prime. Parameters: @@ -33,7 +33,7 @@ def is_prime(n: int) -> bool: return True def find_primes_up_to_n(n: int) -> list: - """ + r""" Finds all prime numbers up to the given number \( N \). Parameters: From e4c91d023d5c103581f9b907dfbe02681a043ece Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Thu, 9 Jan 2025 22:57:40 +0200 Subject: [PATCH 13/32] Update Find-Prime-Numbers.py --- solutions/Find-Prime-Numbers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/Find-Prime-Numbers.py b/solutions/Find-Prime-Numbers.py index 6c9207607..a53c8fe5f 100644 --- a/solutions/Find-Prime-Numbers.py +++ b/solutions/Find-Prime-Numbers.py @@ -4,8 +4,8 @@ This module defines the function `find_primes_up_to_n` to identify all prime numbers up to a given integer \( N \). A prime number is greater than 1 and divisible only by 1 and itself. -Author: Zeinab Shadabshoar Date: 09 01 2025 +Author: Zeinab Shadabshoar """ From 4ddf84c083b57bb1cd5a259227432dbb0b9e172c Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Thu, 9 Jan 2025 23:09:48 +0200 Subject: [PATCH 14/32] Update Find-Prime-Numbers.py --- solutions/Find-Prime-Numbers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/solutions/Find-Prime-Numbers.py b/solutions/Find-Prime-Numbers.py index a53c8fe5f..d21fd42e3 100644 --- a/solutions/Find-Prime-Numbers.py +++ b/solutions/Find-Prime-Numbers.py @@ -10,6 +10,7 @@ def is_prime(n: int) -> bool: + r""" Checks if a given number is prime. @@ -33,6 +34,7 @@ def is_prime(n: int) -> bool: return True def find_primes_up_to_n(n: int) -> list: + r""" Finds all prime numbers up to the given number \( N \). From ea00a141ea56e94b6937a38ce2d5711e0d530598 Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Fri, 10 Jan 2025 11:22:22 +0200 Subject: [PATCH 15/32] Add files via upload --- solutions/__init__.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 solutions/__init__.py diff --git a/solutions/__init__.py b/solutions/__init__.py new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/solutions/__init__.py @@ -0,0 +1 @@ + From 07c4d710155addc601adb9de074b4e4d2590c2f0 Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Fri, 10 Jan 2025 11:46:00 +0200 Subject: [PATCH 16/32] Add files via upload --- solutions/tests/test_find_prime_numbers.py | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 solutions/tests/test_find_prime_numbers.py diff --git a/solutions/tests/test_find_prime_numbers.py b/solutions/tests/test_find_prime_numbers.py new file mode 100644 index 000000000..a39b210e3 --- /dev/null +++ b/solutions/tests/test_find_prime_numbers.py @@ -0,0 +1,82 @@ +""" +A module for testing the functions decimal_to_binary and binary_to_decimal. + +Tests included: + - decimal_to_binary: tested the cases when the input is a positive random number, + input is a negative integer, input is zero, and when the input is a string. + - binary_to_decimal: tested the cases when the input is a random binary number, + input is a zero, and when the input is a string. + +Created on 31 12 24 +@author: Abdallah Alnajjar +""" + +import unittest + +from ..num_converter import binary_to_decimal, decimal_to_binary + + +class TestBinaryDecimalConversion(unittest.TestCase): + """ + Tests both functions in num_converter, binary_to_decimal and decimal_to_binary. + """ + + def test_decimal_to_binary_247(self): + """ + It should return a binary representation of 11110111 + """ + actual = decimal_to_binary(247) + expected = 11110111 + self.assertEqual(actual, expected) + + def test_decimal_to_binary_zero(self): + """ + It should return a binary representation of 11110111 + """ + actual = decimal_to_binary(0) + expected = 0 + self.assertEqual(actual, expected) + + def test_decimal_to_binary_string(self): + """ + It should raise an assertion error if the input is a non-integer + """ + with self.assertRaises(AssertionError): + decimal_to_binary("Abdallah") + + def test_decimal_to_binary_negative(self): + """ + It should raise an assertion error if the input is a negative integer + """ + with self.assertRaises(AssertionError): + decimal_to_binary(-255) + + def test_binary_to_decimal_1111(self): + """ + It should return 15 if the input is 1111 + """ + actual = binary_to_decimal(1111) + expected = 15 + self.assertEqual(actual, expected) + + def test_binary_to_decimal_zeros(self): + """ + It should return 0 if the input is zero + """ + actual = binary_to_decimal(0) + expected = 0 + self.assertEqual(actual, expected) + + def test_binary_to_decimal_non_binary(self): + """ + It should raise an assertion error if the input contains digits other than 0 and 1 + """ + with self.assertRaises(AssertionError): + binary_to_decimal(20105140) + + def test_binary_to_decimal_non_integer(self): + """ + It should raise an assertion error if the input is a non-integer + """ + with self.assertRaises(AssertionError): + binary_to_decimal("Aboodi") From a19257f7f706625f84f652d2be9914bfc292902c Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Fri, 10 Jan 2025 11:46:49 +0200 Subject: [PATCH 17/32] Update test_find_prime_numbers.py --- solutions/tests/test_find_prime_numbers.py | 91 ++++++++++++---------- 1 file changed, 52 insertions(+), 39 deletions(-) diff --git a/solutions/tests/test_find_prime_numbers.py b/solutions/tests/test_find_prime_numbers.py index a39b210e3..705816815 100644 --- a/solutions/tests/test_find_prime_numbers.py +++ b/solutions/tests/test_find_prime_numbers.py @@ -1,82 +1,95 @@ """ -A module for testing the functions decimal_to_binary and binary_to_decimal. +A module for testing the functions is_prime and find_primes_up_to_n. Tests included: - - decimal_to_binary: tested the cases when the input is a positive random number, - input is a negative integer, input is zero, and when the input is a string. - - binary_to_decimal: tested the cases when the input is a random binary number, - input is a zero, and when the input is a string. + - is_prime: tested the cases when the input is a prime number, a non-prime number, + input is zero, input is one, input is a negative integer, and when the input is a string. + - find_primes_up_to_n: tested the cases when the input is a positive integer, + input is zero, and when the input is a string. -Created on 31 12 24 -@author: Abdallah Alnajjar +Created on 10 01 2025 +@author: Zeinab Shadabshoar """ import unittest -from ..num_converter import binary_to_decimal, decimal_to_binary +from ..prime_checker import is_prime, find_primes_up_to_n -class TestBinaryDecimalConversion(unittest.TestCase): +class TestPrimeFunctions(unittest.TestCase): """ - Tests both functions in num_converter, binary_to_decimal and decimal_to_binary. + Tests both functions in prime_checker, is_prime and find_primes_up_to_n. """ - def test_decimal_to_binary_247(self): + def test_is_prime_prime(self): """ - It should return a binary representation of 11110111 + It should return True if the input is a prime number """ - actual = decimal_to_binary(247) - expected = 11110111 + actual = is_prime(7) + expected = True self.assertEqual(actual, expected) - def test_decimal_to_binary_zero(self): + def test_is_prime_non_prime(self): """ - It should return a binary representation of 11110111 + It should return False if the input is a non-prime number """ - actual = decimal_to_binary(0) - expected = 0 + actual = is_prime(4) + expected = False self.assertEqual(actual, expected) - def test_decimal_to_binary_string(self): + def test_is_prime_zero(self): """ - It should raise an assertion error if the input is a non-integer + It should return False if the input is zero """ - with self.assertRaises(AssertionError): - decimal_to_binary("Abdallah") + actual = is_prime(0) + expected = False + self.assertEqual(actual, expected) + + def test_is_prime_one(self): + """ + It should return False if the input is one + """ + actual = is_prime(1) + expected = False + self.assertEqual(actual, expected) - def test_decimal_to_binary_negative(self): + def test_is_prime_negative(self): """ It should raise an assertion error if the input is a negative integer """ with self.assertRaises(AssertionError): - decimal_to_binary(-255) + is_prime(-5) - def test_binary_to_decimal_1111(self): + def test_is_prime_string(self): """ - It should return 15 if the input is 1111 + It should raise an assertion error if the input is a non-integer """ - actual = binary_to_decimal(1111) - expected = 15 - self.assertEqual(actual, expected) + with self.assertRaises(AssertionError): + is_prime("Zeinab") - def test_binary_to_decimal_zeros(self): + def test_find_primes_up_to_n_positive(self): """ - It should return 0 if the input is zero + It should return a list of prime numbers up to the given positive integer """ - actual = binary_to_decimal(0) - expected = 0 + actual = find_primes_up_to_n(20) + expected = [2, 3, 5, 7, 11, 13, 17, 19] self.assertEqual(actual, expected) - def test_binary_to_decimal_non_binary(self): + def test_find_primes_up_to_n_zero(self): """ - It should raise an assertion error if the input contains digits other than 0 and 1 + It should return an empty list if the input is zero """ - with self.assertRaises(AssertionError): - binary_to_decimal(20105140) + actual = find_primes_up_to_n(0) + expected = [] + self.assertEqual(actual, expected) - def test_binary_to_decimal_non_integer(self): + def test_find_primes_up_to_n_string(self): """ It should raise an assertion error if the input is a non-integer """ with self.assertRaises(AssertionError): - binary_to_decimal("Aboodi") + find_primes_up_to_n("Twenty") + +if __name__ == '__main__': + unittest.main() + From 1b846b8fffd8b12de6a520ef4c2df3bd817cf392 Mon Sep 17 00:00:00 2001 From: ShadiShadab Date: Fri, 10 Jan 2025 12:24:26 +0200 Subject: [PATCH 18/32] update --- .../{Find-Prime-Numbers.py => find_prime_numbers.py} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename solutions/{Find-Prime-Numbers.py => find_prime_numbers.py} (97%) diff --git a/solutions/Find-Prime-Numbers.py b/solutions/find_prime_numbers.py similarity index 97% rename from solutions/Find-Prime-Numbers.py rename to solutions/find_prime_numbers.py index d21fd42e3..9bb4c0591 100644 --- a/solutions/Find-Prime-Numbers.py +++ b/solutions/find_prime_numbers.py @@ -1,16 +1,15 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- r""" -This module defines the function `find_primes_up_to_n` to identify all prime numbers +This module defines the function `find_primes_up_to_n` to identify all prime numbers up to a given integer \( N \). A prime number is greater than 1 and divisible only by 1 and itself. -Date: 09 01 2025 Author: Zeinab Shadabshoar +Date: 09 01 2025 """ def is_prime(n: int) -> bool: - r""" Checks if a given number is prime. @@ -33,8 +32,8 @@ def is_prime(n: int) -> bool: return False return True + def find_primes_up_to_n(n: int) -> list: - r""" Finds all prime numbers up to the given number \( N \). @@ -54,6 +53,7 @@ def find_primes_up_to_n(n: int) -> list: primes.append(num) return primes + # Example usage N = 20 print("Prime numbers up to", N, ":", find_primes_up_to_n(N)) From 7189986663b8081e283c2abd95d646ed42fade5c Mon Sep 17 00:00:00 2001 From: ShadiShadab Date: Fri, 10 Jan 2025 13:07:31 +0200 Subject: [PATCH 19/32] Update find prime --- .vscode/tasks.json | 15 +++++++++++++++ collaboration/constraints.md | 6 +++--- collaboration/learning_goals.md | 5 +++++ solutions/find_prime_numbers.py | 6 ++++-- solutions/tests/test_find_prime_numbers.py | 6 +++--- 5 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 .vscode/tasks.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 000000000..6fc0ced9f --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Run Ruff", + "type": "shell", + "command": "ruff --fix . || true", + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} diff --git a/collaboration/constraints.md b/collaboration/constraints.md index eca4af3eb..fb2c46546 100644 --- a/collaboration/constraints.md +++ b/collaboration/constraints.md @@ -22,7 +22,7 @@ Some boundaries around our project. | Mohammad | Time management | | Kimya | Time management | | Asia | Internet connectivity and no laptop | -| Member | Constraints | +| Shadi | Work, Internet connectivity| ## Internal: Involuntary @@ -39,7 +39,7 @@ Some boundaries around our project. | Mohammad | New to GitHub | | Kimya | New to Python and Github | | Asia | Using a phone to do a project | -| Member | Constraints | +| Shadi | New to Github & Python | ## Internal: Voluntary @@ -57,4 +57,4 @@ Some boundaries around our project. | Mohammad | The code difficulty | | Kimya | The code difficulty | | Asia | The organization of the project | -| Member | Constraints | +| Shadi | The code difficulty | diff --git a/collaboration/learning_goals.md b/collaboration/learning_goals.md index a667bdb3c..cba89cd3d 100644 --- a/collaboration/learning_goals.md +++ b/collaboration/learning_goals.md @@ -43,3 +43,8 @@ - Become proficient in using Git and GitHub to enhance my knowledge and potential in writing and reviewing code. - Enhance problem-solving skills by collaboration with team. + +### **Shadi** + +- Programming Proficiency +- Proficiency in Github & Python diff --git a/solutions/find_prime_numbers.py b/solutions/find_prime_numbers.py index 9bb4c0591..cbecd390e 100644 --- a/solutions/find_prime_numbers.py +++ b/solutions/find_prime_numbers.py @@ -25,7 +25,9 @@ def is_prime(n: int) -> bool: >>> is_prime(4) False """ - if n <= 1: + print(type(n)) + + if int(n) <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: @@ -48,7 +50,7 @@ def find_primes_up_to_n(n: int) -> list: [2, 3, 5, 7, 11, 13, 17, 19] """ primes = [] - for num in range(2, n + 1): + for num in range(2, int(n + 1)): if is_prime(num): primes.append(num) return primes diff --git a/solutions/tests/test_find_prime_numbers.py b/solutions/tests/test_find_prime_numbers.py index 705816815..fe8a6f047 100644 --- a/solutions/tests/test_find_prime_numbers.py +++ b/solutions/tests/test_find_prime_numbers.py @@ -13,7 +13,7 @@ import unittest -from ..prime_checker import is_prime, find_primes_up_to_n +from ..find_prime_numbers import find_primes_up_to_n, is_prime class TestPrimeFunctions(unittest.TestCase): @@ -90,6 +90,6 @@ def test_find_primes_up_to_n_string(self): with self.assertRaises(AssertionError): find_primes_up_to_n("Twenty") -if __name__ == '__main__': - unittest.main() +if __name__ == "__main__": + unittest.main() From 23a67de0f5c5dca0d066a303eadb2b6ed1588463 Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Fri, 10 Jan 2025 13:12:24 +0200 Subject: [PATCH 20/32] Update find_prime_numbers.py From 60b857cead3389e99e64266656f2ae3f2e5f6126 Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Fri, 10 Jan 2025 13:18:40 +0200 Subject: [PATCH 21/32] Update test_find_prime_numbers.py From 070624f62d19b4e85a24207a6fe19f62a68cf0b0 Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Fri, 10 Jan 2025 14:00:28 +0200 Subject: [PATCH 22/32] Update find_prime_numbers.py --- solutions/find_prime_numbers.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/solutions/find_prime_numbers.py b/solutions/find_prime_numbers.py index cbecd390e..88cbc64b9 100644 --- a/solutions/find_prime_numbers.py +++ b/solutions/find_prime_numbers.py @@ -36,7 +36,7 @@ def is_prime(n: int) -> bool: def find_primes_up_to_n(n: int) -> list: - r""" + """ Finds all prime numbers up to the given number \( N \). Parameters: @@ -49,8 +49,11 @@ def find_primes_up_to_n(n: int) -> list: >>> find_primes_up_to_n(20) [2, 3, 5, 7, 11, 13, 17, 19] """ + assert isinstance(n, int), "Input must be an integer" + assert n >= 0, "Input must be a non-negative integer" + primes = [] - for num in range(2, int(n + 1)): + for num in range(2, n + 1): if is_prime(num): primes.append(num) return primes From 70577ce712fcaa38341768fd6bdcfb1d6fa977ec Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Fri, 10 Jan 2025 14:23:05 +0200 Subject: [PATCH 23/32] Update test_find_prime_numbers.py --- solutions/tests/test_find_prime_numbers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/tests/test_find_prime_numbers.py b/solutions/tests/test_find_prime_numbers.py index fe8a6f047..2da7d83b2 100644 --- a/solutions/tests/test_find_prime_numbers.py +++ b/solutions/tests/test_find_prime_numbers.py @@ -65,7 +65,7 @@ def test_is_prime_string(self): It should raise an assertion error if the input is a non-integer """ with self.assertRaises(AssertionError): - is_prime("Zeinab") + is_prime(self) def test_find_primes_up_to_n_positive(self): """ From c4af6a7440e4fd7015dc527797643df2ab15aef0 Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Fri, 10 Jan 2025 14:37:29 +0200 Subject: [PATCH 24/32] Update find_prime_numbers.py --- solutions/find_prime_numbers.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/solutions/find_prime_numbers.py b/solutions/find_prime_numbers.py index 88cbc64b9..f2692c010 100644 --- a/solutions/find_prime_numbers.py +++ b/solutions/find_prime_numbers.py @@ -7,7 +7,11 @@ Author: Zeinab Shadabshoar Date: 09 01 2025 """ - +def find_primes_up_to_n(n): + if not isinstance(n, int): + raise TypeError("Input must be an integer") + if n <= 1: + return [] def is_prime(n: int) -> bool: r""" From dab3eacad32bea0aa4ae83cba3c7780f4c5a53a0 Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Fri, 10 Jan 2025 14:42:27 +0200 Subject: [PATCH 25/32] Update find_prime_numbers.py --- solutions/find_prime_numbers.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/solutions/find_prime_numbers.py b/solutions/find_prime_numbers.py index f2692c010..a9253563a 100644 --- a/solutions/find_prime_numbers.py +++ b/solutions/find_prime_numbers.py @@ -7,11 +7,7 @@ Author: Zeinab Shadabshoar Date: 09 01 2025 """ -def find_primes_up_to_n(n): - if not isinstance(n, int): - raise TypeError("Input must be an integer") - if n <= 1: - return [] + def is_prime(n: int) -> bool: r""" @@ -29,9 +25,11 @@ def is_prime(n: int) -> bool: >>> is_prime(4) False """ - print(type(n)) + # Ensure n is an integer + if not isinstance(n, int): + raise TypeError("Input must be an integer") - if int(n) <= 1: + if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: @@ -40,7 +38,7 @@ def is_prime(n: int) -> bool: def find_primes_up_to_n(n: int) -> list: - """ + r""" Finds all prime numbers up to the given number \( N \). Parameters: @@ -53,8 +51,11 @@ def find_primes_up_to_n(n: int) -> list: >>> find_primes_up_to_n(20) [2, 3, 5, 7, 11, 13, 17, 19] """ - assert isinstance(n, int), "Input must be an integer" - assert n >= 0, "Input must be a non-negative integer" + # Ensure n is an integer and non-negative + if not isinstance(n, int): + raise TypeError("Input must be an integer") + if n < 0: + raise ValueError("Input must be a non-negative integer") primes = [] for num in range(2, n + 1): From 91a95c185e1811802d8cedcf3b1005464a1a707f Mon Sep 17 00:00:00 2001 From: theabdallahnjr Date: Sat, 11 Jan 2025 10:03:02 +0200 Subject: [PATCH 26/32] solved some issues --- solutions/github/workflows/ci.yml | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 solutions/github/workflows/ci.yml diff --git a/solutions/github/workflows/ci.yml b/solutions/github/workflows/ci.yml deleted file mode 100644 index c5eb74b56..000000000 --- a/solutions/github/workflows/ci.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: CI - -on: [push, pull_request] - -jobs: - lint-and-format: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.x' # Specify the Python version you need - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install black pylint markdownlint-cli - - - name: Format code with black - run: black your_script.py - - - name: Lint code with pylint - run: pylint your_script.py - - - name: Check markdown formatting - run: markdownlint **/*.md From 1eb5d080e5cd9b4b31dad6b194490a0dfcacea3e Mon Sep 17 00:00:00 2001 From: Abdallah Alnajjar Date: Sat, 11 Jan 2025 10:08:41 +0200 Subject: [PATCH 27/32] Update find_prime_numbers.py --- solutions/find_prime_numbers.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/solutions/find_prime_numbers.py b/solutions/find_prime_numbers.py index a9253563a..67663c5a6 100644 --- a/solutions/find_prime_numbers.py +++ b/solutions/find_prime_numbers.py @@ -27,7 +27,7 @@ def is_prime(n: int) -> bool: """ # Ensure n is an integer if not isinstance(n, int): - raise TypeError("Input must be an integer") + raise AssertionError("Input must be an integer") if n <= 1: return False @@ -53,17 +53,12 @@ def find_primes_up_to_n(n: int) -> list: """ # Ensure n is an integer and non-negative if not isinstance(n, int): - raise TypeError("Input must be an integer") + raise AssertionError("Input must be an integer") if n < 0: - raise ValueError("Input must be a non-negative integer") + raise AssertionError("Input must be a non-negative integer") primes = [] for num in range(2, n + 1): if is_prime(num): primes.append(num) return primes - - -# Example usage -N = 20 -print("Prime numbers up to", N, ":", find_primes_up_to_n(N)) From 15512d29288e8f92b4b896c5cc0e094621141336 Mon Sep 17 00:00:00 2001 From: Abdallah Alnajjar Date: Sat, 11 Jan 2025 11:19:57 +0200 Subject: [PATCH 28/32] Update test_find_prime_numbers.py --- solutions/tests/test_find_prime_numbers.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/solutions/tests/test_find_prime_numbers.py b/solutions/tests/test_find_prime_numbers.py index 2da7d83b2..4933d7404 100644 --- a/solutions/tests/test_find_prime_numbers.py +++ b/solutions/tests/test_find_prime_numbers.py @@ -53,13 +53,6 @@ def test_is_prime_one(self): expected = False self.assertEqual(actual, expected) - def test_is_prime_negative(self): - """ - It should raise an assertion error if the input is a negative integer - """ - with self.assertRaises(AssertionError): - is_prime(-5) - def test_is_prime_string(self): """ It should raise an assertion error if the input is a non-integer From 1730044f7566ebcba1e619f524d32328976c69b7 Mon Sep 17 00:00:00 2001 From: Abdallah Alnajjar Date: Sat, 11 Jan 2025 11:21:45 +0200 Subject: [PATCH 29/32] Update find_prime_numbers.py --- solutions/find_prime_numbers.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/solutions/find_prime_numbers.py b/solutions/find_prime_numbers.py index 67663c5a6..dc980c063 100644 --- a/solutions/find_prime_numbers.py +++ b/solutions/find_prime_numbers.py @@ -4,8 +4,6 @@ This module defines the function `find_primes_up_to_n` to identify all prime numbers up to a given integer \( N \). A prime number is greater than 1 and divisible only by 1 and itself. -Author: Zeinab Shadabshoar -Date: 09 01 2025 """ From 3d519eed6fb0b764b9fbe5c7f9705fdae23b2039 Mon Sep 17 00:00:00 2001 From: Shadi Shadab <46791602+ShadiShadab@users.noreply.github.com> Date: Sat, 11 Jan 2025 19:14:14 +0200 Subject: [PATCH 30/32] Update find_prime_numbers.py --- solutions/find_prime_numbers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/solutions/find_prime_numbers.py b/solutions/find_prime_numbers.py index dc980c063..f20948fb5 100644 --- a/solutions/find_prime_numbers.py +++ b/solutions/find_prime_numbers.py @@ -4,6 +4,8 @@ This module defines the function `find_primes_up_to_n` to identify all prime numbers up to a given integer \( N \). A prime number is greater than 1 and divisible only by 1 and itself. +@uthor: Zeinab Shadabshoar +Date: 10 01 2025 """ From fe5a2ea4868b452615dc94105374e619f86fd84f Mon Sep 17 00:00:00 2001 From: Abdallah Alnajjar Date: Sat, 11 Jan 2025 20:22:18 +0200 Subject: [PATCH 31/32] Update constraints.md --- collaboration/constraints.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/collaboration/constraints.md b/collaboration/constraints.md index 2c458633e..fb2c46546 100644 --- a/collaboration/constraints.md +++ b/collaboration/constraints.md @@ -41,8 +41,6 @@ Some boundaries around our project. | Asia | Using a phone to do a project | | Shadi | New to Github & Python | - - ## Internal: Voluntary