Skip to content

Commit

Permalink
Merge branch 'main' into find_prime_numbers_up_to_n
Browse files Browse the repository at this point in the history
  • Loading branch information
theabdallahnjr authored Jan 11, 2025
2 parents 3d519ee + e1c42e0 commit 946786b
Show file tree
Hide file tree
Showing 25 changed files with 1,247 additions and 7 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,8 @@
"source.fixAll.ruff": "explicit",
"source.organizeImports.ruff": "explicit"
}
}
},
"python.testing.unittestArgs": ["-v", "-s", ".", "-p", "*test.py"],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
}
8 changes: 4 additions & 4 deletions collaboration/communication.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ______________________________________________________________________
| **Abdallah** | 6 PM - 8 PM (2h) | 6 PM - 8 PM (2h) | 6 PM - 8 PM (2h) |
| **Kimya** | 10 AM - 12 PM (2h)| 11 AM - 1 PM (2h) | 10 AM - 12 PM (2h)|
| **Mohammad** | 2 PM - 4 PM (2h) | 2 PM - 4 PM (2h) | 7 PM - 10 PM (2h) |
| **Member 5** | 5h | 6h | 5h |
| **Shadi** | 11 AM - 4 PM | 11 AM - 4 PM | 11 AM - 4 PM |
| **Member 6** | 5h | 6h | 5h |
| **Member 7** | 5h | 6h | 5h |

Expand All @@ -67,7 +67,7 @@ ______________________________________________________________________
| **Abdallah** | 6 PM - 8 PM (2h) | 6 PM - 8 PM (2h) | 10 AM - 17 PM (7h)|
| **Mohammad** | 10 AM - 12 PM (2h)| 9 AM - 11 PM (2h) | 12 PM - 2 PM (2h) |
| **Kimya** | 10 AM - 12 PM | 11 AM - 1 PM | 10 AM - 12 PM |
| **Member 5** | 4h | 3h | 5h |
| **Shadi** | 11 AM - 4 PM | 11 AM - 4 PM | 12 PM - 8 PM |
| **Member 6** | 4h | 3h | 5h |
| **Member 7** | 4h | 3h | 5h |

Expand All @@ -79,7 +79,7 @@ ______________________________________________________________________
| **Abdallah** | 10 AM - 17 PM (7h) |
| **Mohammad** | 2 PM - 4 PM (2h) |
| **Kimya** | 11 AM - 1 PM |
| **Member 5** | 4h |
| **Shadi** | 12 PM - 8 PM |
| **Member 6** | 4h |
| **Member 7** | 4h |

Expand All @@ -89,7 +89,7 @@ ______________________________________________________________________
- **Abdallah**: 2-3 hrs
- **Mohammad**: 2h
- **Kimya**: 2h
- **Member 5**: 5h
- **Shadi**: 2h
- **Member 6**: 5h
- **Member 7**: 5h

Expand Down
4 changes: 4 additions & 0 deletions collaboration/constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Some boundaries around our project.
| Asia | Using a phone to do a project |
| Shadi | New to Github & Python |


Check failure on line 44 in collaboration/constraints.md

View workflow job for this annotation

GitHub Actions / md_formatting

Multiple consecutive blank lines [Expected: 1; Actual: 2]

Check failure on line 44 in collaboration/constraints.md

View workflow job for this annotation

GitHub Actions / md_formatting

Multiple consecutive blank lines [Expected: 1; Actual: 2]

Check failure on line 45 in collaboration/constraints.md

View workflow job for this annotation

GitHub Actions / md_formatting

Multiple consecutive blank lines [Expected: 1; Actual: 3]

Check failure on line 45 in collaboration/constraints.md

View workflow job for this annotation

GitHub Actions / md_formatting

Multiple consecutive blank lines [Expected: 1; Actual: 3]
## Internal: Voluntary

<!--
Expand All @@ -58,3 +60,5 @@ Some boundaries around our project.
| Kimya | The code difficulty |
| Asia | The organization of the project |
| Shadi | The code difficulty |


Check failure on line 64 in collaboration/constraints.md

View workflow job for this annotation

GitHub Actions / md_formatting

Multiple consecutive blank lines [Expected: 1; Actual: 2]

Check failure on line 64 in collaboration/constraints.md

View workflow job for this annotation

GitHub Actions / md_formatting

Multiple consecutive blank lines [Expected: 1; Actual: 2]
1 change: 1 addition & 0 deletions collaboration/learning_goals.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@

- Programming Proficiency
- Proficiency in Github & Python

11 changes: 11 additions & 0 deletions solutions/Square_Root_Floor
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import math

def floor_sqrt(numbers):
result = []
for num in numbers:
if num < 0:
result.append(None)
else:
sqrt_value = math.sqrt(num)
result.append(math.floor(sqrt_value))
return result
1 change: 0 additions & 1 deletion solutions/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

41 changes: 41 additions & 0 deletions solutions/count_consonants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
This module defines the function `count_consonants` to count the number of consonants
in a given string. The function handles different character cases and ignores non-alphabetical characters.
Author: Norbert Ndayisenga
Date: 07 01 2024
"""


def count_consonants(s: str) -> int:
"""
Counts the number of consonants in a given string, ignoring vowels, numbers, and symbols.
Parameters:
s (str): The input string to evaluate.
Returns:
int: The number of consonants in the input string.
Raises:
TypeError: If the input is not a string.
Examples:
>>> count_consonants("Hello, World!")
7
>>> count_consonants("123@#$")
0
>>> count_consonants("bcdfghjklmnpqrstvwxyz")
21
"""
# Ensure the input is a string
if not isinstance(s, str):
raise TypeError("Input must be a string")

# Define consonants using a set for faster membership testing
consonants = set("bcdfghjklmnpqrstvwxyz")

# Count consonants in the string
return sum(1 for char in s.lower() if char in consonants)
38 changes: 38 additions & 0 deletions solutions/count_even_numbers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
This module defines the function `count_evens` to count the number of even integers
in a given list. The function ignores non-integer elements and handles invalid input gracefully.
Author: Norbert Ndayisenga
Date: 07 01 2024
"""


def count_evens(numbers: list) -> int:
"""
Counts the number of even integers in a given list, ignoring non-integer elements.
Parameters:
numbers (list): The input list to evaluate.
Returns:
int: The number of even integers in the input list.
Raises:
TypeError: If the input is not a list.
Examples:
>>> count_evens([1, 2, 3, 4])
2
>>> count_evens([1, 'a', None, 2.5])
0
>>> count_evens([2, 4, 6])
3
"""
# Ensure the input is a list
if not isinstance(numbers, list):
raise TypeError("Input must be a list")

# Count even integers in the list
return sum(1 for num in numbers if isinstance(num, int) and num % 2 == 0)
75 changes: 75 additions & 0 deletions solutions/count_prime_numbers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
r"""
This module defines the functions `is_prime` and `count_primes` for checking primality
and counting prime numbers in a list.
@uthor: Zeinab Shadabshoar
Date: 09 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.
Raises:
TypeError: If the input is not an integer.
ValueError: If the input is a negative integer.
Examples:
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
if not isinstance(n, int):
raise TypeError("Input must be an integer")
if n < 0:
raise ValueError("Input must be a non-negative 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 count_primes(numbers: list) -> int:
r"""
Counts the number of prime numbers in a list.
Parameters:
numbers (list): The list of numbers to check.
Returns:
int: The count of prime numbers in the list.
Raises:
TypeError: If the input is not a list or contains non-integer elements.
Examples:
>>> count_primes([2, 3, 4, 5])
3
"""
if not isinstance(numbers, list):
raise TypeError("Input must be a list")
prime_count = 0
for num in numbers:
if not isinstance(num, int):
raise TypeError("All elements in the list must be integers")
if is_prime(num):
prime_count += 1
return prime_count


# Example usage
numbers = [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]
print("Number of prime numbers:", count_primes(numbers))
43 changes: 43 additions & 0 deletions solutions/count_the_number_of_words.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3
# -- coding: utf-8 --
"""
A module for counting the number of words in a string.
Module contents:
- word_count_function: takes a string as an argument and returns the number of words.
Created on 06/01/2025
@author: Mohamad Ziadah
"""


def word_count_function(s: str) -> int:
"""
Counts the number of words in a string.
Parameters:
s (str): The input string to count words from.
Returns:
int: The number of words in the string.
Raises:
AssertionError: If the input is not a string.
>>> word_count_function("The quick brown fox jumps over the lazy dog")
9
>>> word_count_function("")
0
>>> word_count_function(" leading and trailing spaces ")
4
>>> word_count_function("word1\tword2\nword3 word4")
4
"""
assert isinstance(s, str), "Input must be a string"

# Filter out non-alphanumeric characters and split the string by whitespace
words = [word for word in s.split() if word.isalnum()]

# Return the count of words
return len(words)
99 changes: 99 additions & 0 deletions solutions/fuel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
"""
This module provides functionality to convert a fraction to
a percentage and display it in a user-friendly format.
Functions:
main(): Entry point of the program that handles user input and output.
convert(fraction): Converts a fraction string (e.g., '1/2') into a percentage.
gauge(percentage): Converts a percentage into a user-friendly string representation.
Author: Alnajjar
Date: 10 01 2025
"""


def main():
"""
Continuously prompts the user for a fraction input, converts it
to a percentage, and displays the result.
"""
while True:
try:
fraction = input("Fraction: ")
print(gauge(convert(fraction)))
break
except AssertionError as e:
print(e)


def convert(fraction):
"""
Converts a fraction string into a percentage.
Args:
fraction (str): A string representing a fraction in the format 'X/Y'.
Returns:
int: The percentage equivalent of the fraction, rounded to the nearest integer.
Raises:
AssertionError: If the numerator is greater than the denominator,
or if the input is invalid.
Examples:
>>> convert("1/2")
50
>>> convert("3/4")
75
>>> convert("2/5")
40
"""
x, y = fraction.split("/")

# Assert that both parts of the fraction are digits
assert x.isdigit() and y.isdigit(), (
"Both numerator and denominator must be integers."
)

x, y = int(x), int(y)

assert y != 0, "Denominator cannot be zero."

assert x >= 0 and y > 0, "Numerator and denominator must be non-negative."

assert x <= y, "Numerator cannot be greater than denominator."

return round((x / y) * 100)


def gauge(percentage):
"""
Converts a percentage into a user-friendly string representation.
Args:
percentage (int): An integer representing a percentage (0-100).
Returns:
str: 'F' if the percentage is greater than 99, 'E' if less than 1,
otherwise the percentage followed by '%'.
Raises:
AssertionError: If the percentage is not within the range 0-100.
Examples:
>>> gauge(50)
'50%'
>>> gauge(100)
'F'
>>> gauge(0)
'E'
"""
# Assert that percentage is within valid range
assert 0 <= percentage <= 100, "Percentage must be between 0 and 100."

if percentage > 99:
return "F"
elif percentage < 1:
return "E"
else:
return f"{percentage}%"
Loading

0 comments on commit 946786b

Please sign in to comment.