My issue
Divisible Number Finder
In this task, you will use List comprehensions to create a function that finds all numbers divisible by a given divisor within a specified range.
List comprehensions provide a concise way to create lists in Python. They can be used to apply an expression to each element in a sequence, often replacing loops and map() functions with more readable and compact code.
Your task is to implement the function find_divisibles(start, end, divisor) that takes three parameters:
start: the beginning of the range (inclusive)
end: the end of the range (inclusive)
divisor: the number to check divisibility against
The function should return a list of all numbers within the given range that are divisible by the specified divisor.
For example, if the input is start=1, end=10, and divisor=3, the output should be [3, 6, 9].
My code
def find_divisibles(start, end, divisor):
# TODO: Implement the function using List comprehension
return [i for i in range(start,end) if i % divisor==0]
if __name__ == "__main__":
start, end, divisor = map(int, input().split())
result = find_divisibles(start, end, divisor)
print(result)
Learning course: Python Coding Challenges
Problem Link: Divisible Number Finder Practice Problem in Python Coding Challenges