Custom Step In For Loop
Tags: Loops Basics
Credit: CodingChallenge
Difficulty: Beginner
Type: Text
Category: Practice
Time Allowed: 5 s
Description:
Write a function that takes a start number, an end number, and a step size, and returns a list of numbers starting from the start number up to but not including the end number, incremented by the step size. This problem is designed to help you practice using custom step sizes in for loops
. The function should accept three parameters and return the list of numbers.
Constraints:
- The start, end, and step inputs will be
integers
. - The step size can be positive or negative, but not zero.
- The function should
return
alist
of numbers generated by the custom step.
Example:
- Input:
0, 10, 2
- Output:
[0, 2, 4, 6, 8]
Test Case | Input | Expected Output |
---|---|---|
1 | [0, 10, 2] | [0, 2, 4, 6, 8] |
2 | [10, 0, -2] | [10, 8, 6, 4, 2] |
3 | [5, 20, 5] | [5, 10, 15] |
4 | [0, -10, -3] | [0, -3, -6, -9] |
5 | [1, 5, 1] | [1, 2, 3, 4] |
Leave a Comment
Please login to leave a comment.