Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find_prime_numbers_up_to_n #56

Merged
merged 34 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f52b33b
Update and rename __init__.py to FindPrimeNumbers.py
ShadiShadab Jan 9, 2025
4bbc2cb
Update README.md
ShadiShadab Jan 9, 2025
3c409cd
Update README.md
ShadiShadab Jan 9, 2025
0f0ea40
Create ci.yml
ShadiShadab Jan 9, 2025
adf66e9
Update FindPrimeNumbers.py
ShadiShadab Jan 9, 2025
5e0c9ca
Update FindPrimeNumbers.py
ShadiShadab Jan 9, 2025
ddd6b85
Update FindPrimeNumbers.py
ShadiShadab Jan 9, 2025
185edf5
Update README.md
ShadiShadab Jan 9, 2025
9ddf90e
Update README.md
ShadiShadab Jan 9, 2025
8f8a667
Update README.md
ShadiShadab Jan 9, 2025
fb4bb4b
Update README.md
ShadiShadab Jan 9, 2025
f723c10
Update and rename FindPrimeNumbers.py to Find-Prime-Numbers.py
ShadiShadab Jan 9, 2025
e4c91d0
Update Find-Prime-Numbers.py
ShadiShadab Jan 9, 2025
4ddf84c
Update Find-Prime-Numbers.py
ShadiShadab Jan 9, 2025
ea00a14
Add files via upload
ShadiShadab Jan 10, 2025
07c4d71
Add files via upload
ShadiShadab Jan 10, 2025
a19257f
Update test_find_prime_numbers.py
ShadiShadab Jan 10, 2025
1b846b8
update
ShadiShadab Jan 10, 2025
7189986
Update find prime
ShadiShadab Jan 10, 2025
23a67de
Update find_prime_numbers.py
ShadiShadab Jan 10, 2025
60b857c
Update test_find_prime_numbers.py
ShadiShadab Jan 10, 2025
070624f
Update find_prime_numbers.py
ShadiShadab Jan 10, 2025
70577ce
Update test_find_prime_numbers.py
ShadiShadab Jan 10, 2025
c4af6a7
Update find_prime_numbers.py
ShadiShadab Jan 10, 2025
dab3eac
Update find_prime_numbers.py
ShadiShadab Jan 10, 2025
91a95c1
solved some issues
theabdallahnjr Jan 11, 2025
a5284b1
Merge branch 'MIT-Emerging-Talent:main' into prime_numbers_testing
theabdallahnjr Jan 11, 2025
1eb5d08
Update find_prime_numbers.py
theabdallahnjr Jan 11, 2025
15512d2
Update test_find_prime_numbers.py
theabdallahnjr Jan 11, 2025
1730044
Update find_prime_numbers.py
theabdallahnjr Jan 11, 2025
3d519ee
Update find_prime_numbers.py
ShadiShadab Jan 11, 2025
946786b
Merge branch 'main' into find_prime_numbers_up_to_n
theabdallahnjr Jan 11, 2025
fe5a2ea
Update constraints.md
theabdallahnjr Jan 11, 2025
6be1718
Update learning_goals.md
theabdallahnjr Jan 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run Ruff",
"type": "shell",
"command": "ruff --fix . || true",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
6 changes: 3 additions & 3 deletions collaboration/constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Some boundaries around our project.
| Mohammad | Time management |
| Kimya | Time management |
| Asia | Internet connectivity and no laptop |
| Shadi | Constraints |
| Shadi | Work, Internet connectivity|

## Internal: Involuntary

Expand All @@ -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 |
| Shadi | Constraints |
| Shadi | New to Github & Python |

## Internal: Voluntary

Expand All @@ -57,4 +57,4 @@ Some boundaries around our project.
| Mohammad | The code difficulty |
| Kimya | The code difficulty |
| Asia | The organization of the project |
| Shadi | Constraints |
| Shadi | The code difficulty |
3 changes: 3 additions & 0 deletions collaboration/learning_goals.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@
- Enhance problem-solving skills by collaboration with team.

### **Shadi**

- Programming Proficiency
- Proficiency in Github & Python
64 changes: 64 additions & 0 deletions solutions/find_prime_numbers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/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.

@uthor: Zeinab Shadabshoar
Date: 10 01 2025
"""


def is_prime(n: int) -> bool:
r"""
Checks if a given number is prime.

Parameters:
n (int): The number to check.

Returns:
bool: True if the number is prime, False otherwise.

Examples:
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
# Ensure n is an integer
if not isinstance(n, int):
raise AssertionError("Input must be an integer")

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: int) -> list:
r"""
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]
"""
# Ensure n is an integer and non-negative
if not isinstance(n, int):
raise AssertionError("Input must be an integer")
if n < 0:
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
88 changes: 88 additions & 0 deletions solutions/tests/test_find_prime_numbers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
"""
A module for testing the functions is_prime and find_primes_up_to_n.

Tests included:
- 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 10 01 2025
@author: Zeinab Shadabshoar
"""

import unittest

from ..find_prime_numbers import find_primes_up_to_n, is_prime


class TestPrimeFunctions(unittest.TestCase):
"""
Tests both functions in prime_checker, is_prime and find_primes_up_to_n.
"""

def test_is_prime_prime(self):
"""
It should return True if the input is a prime number
"""
actual = is_prime(7)
expected = True
self.assertEqual(actual, expected)

def test_is_prime_non_prime(self):
"""
It should return False if the input is a non-prime number
"""
actual = is_prime(4)
expected = False
self.assertEqual(actual, expected)

def test_is_prime_zero(self):
"""
It should return False if the input is zero
"""
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_is_prime_string(self):
"""
It should raise an assertion error if the input is a non-integer
"""
with self.assertRaises(AssertionError):
is_prime(self)

def test_find_primes_up_to_n_positive(self):
"""
It should return a list of prime numbers up to the given positive integer
"""
actual = find_primes_up_to_n(20)
expected = [2, 3, 5, 7, 11, 13, 17, 19]
self.assertEqual(actual, expected)

def test_find_primes_up_to_n_zero(self):
"""
It should return an empty list if the input is zero
"""
actual = find_primes_up_to_n(0)
expected = []
self.assertEqual(actual, expected)

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):
find_primes_up_to_n("Twenty")


if __name__ == "__main__":
unittest.main()
Loading