![]() |
VOOZH | about |
Given two integers, start and end, the task is to print all positive numbers between the given range, including both endpoints. For Examples:
Input: start = -5, end = 3
Output: [1, 2, 3]
Below are the different methods to solve this problem:
List comprehension iterates over the range, selects numbers greater than zero, and stores them in a list.
[1, 2, 3]
Explanation:
The filter() function applies a condition to each element of the range. It returns only elements that satisfy the condition.
[1, 2, 3]
Explanation:
This approach uses a simple loop to check each number in the given range and print it if it’s positive.
1 2 3
Explanation: Iterates from start to end, prints the number only if it’s greater than zero.
A while loop can also be used to iterate manually from start to end and print positive numbers.
1 2 3
Explanation: Increments start in each step, printing only positive numbers until the range ends.