File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ from typing import List
2+
3+ def find_numbers (numbers : List [int ], divisible_by : int , not_multiple_of : int ) -> str :
4+ """
5+ Finds all numbers in the given list that are divisible by `divisible_by`
6+ but not a multiple of `not_multiple_of`. Returns them as a comma-separated string.
7+
8+ Args:
9+ numbers (List[int]): The list of numbers to check.
10+ divisible_by (int): The divisor to filter numbers that are divisible.
11+ not_multiple_of (int): The number that filtered numbers should not be a multiple of.
12+
13+ Returns:
14+ str: A comma-separated string of valid numbers.
15+ """
16+ if not numbers :
17+ return "" # Return empty string for an empty list
18+
19+ # List comprehension for efficient filtering
20+ valid_numbers = [str (num ) for num in numbers if num % divisible_by == 0 and num % not_multiple_of != 0 ]
21+
22+ return "," .join (valid_numbers ) # Join the numbers as a single string
23+
24+
25+ if __name__ == "__main__" :
26+ # Define the range of numbers to check
27+ numbers_range = list (range (2000 , 3201 ))
28+
29+ # Set conditions: Divisible by 7 but not a multiple of 5
30+ result = find_numbers (numbers_range , divisible_by = 7 , not_multiple_of = 5 )
31+
32+ # Print the result to standard output
33+ print (result )
You can’t perform that action at this time.
0 commit comments