31.0k views
0 votes
Will range (18,6,-3) end with 9?
a) Yes
b) No

User Thalm
by
8.1k points

2 Answers

2 votes

Answer:

b) No

Step-by-step explanation:

The range (18, 6, -3) does not end with 9 because the numbers in the range are 18, 6, and -3. The last number in the range is -3, not 9.

User Antoine Pelletier
by
8.5k points
2 votes

Final answer:

The range(18,6,-3) in Python will indeed include the number 9, as it starts at 18 and decrements by 3 down to but not including the end value, 6.

Step-by-step explanation:

The range function in Python generates a sequence of numbers starting with the first parameter, ending with one less than the second parameter, and incrementing by the third parameter when the third parameter is provided. In the case of range(18,6,-3), the sequence starts at 18 and should decrement by 3 each time.

Since 18 is the start value, the subsequent values would be 15, 12, and so on, reducing by 3 each time until it reaches a value less than 6 (the end parameter). Therefore, 9 would be included in this sequence as it is reached before the end value of 6 and is a correct decrement from the previous number in the series (12), which is part of a sequence including 18, 15, 12, and 9. Thus, the answer to "Will range(18,6,-3) end with 9?" is "Yes".

User Danniella
by
8.0k points

No related questions found