+ 1

Trying range. isn't working

print(list(range(5,20,-2)))

30th May 2021, 1:56 PM
Joel Sebastian Jijo
Joel Sebastian Jijo - avatar
6 ответов
+ 5
Joel Sebastian Jijo Range means numbers between two values. So here 5 is min value and 20 is max value so range will return list of numbers between these two values. Here 2 means list will be like 5, 7, 9, 11 but here is minus sign (-) so this range (5, 20, -2) will return empty list So if you want in reverse order then do this print(list(range(20, 5, -2))) Now here 20 will be considered as max value and 5 will be considered as min value so you will get list in reverse order.
30th May 2021, 2:18 PM
A͢J
A͢J - avatar
+ 2
range function takes variable number of arguments. When you pass one single argument, it is range(end) The start is default as 0 and the step is default as 1 When you passes two arguments, it is range(start, end) The step is default as 1. When you passes three arguments, it i range(start, end, step)
31st May 2021, 1:21 PM
Gordon
Gordon - avatar
+ 1
Try range(20,5,-2) or range(5,20,2)
30th May 2021, 2:01 PM
TOLUENE
TOLUENE - avatar
+ 1
From 20 to 5 Use range(20,4,-1)
30th May 2021, 2:05 PM
TOLUENE
TOLUENE - avatar
0
I want to get the numbers backward.
30th May 2021, 2:02 PM
Joel Sebastian Jijo
Joel Sebastian Jijo - avatar
0
Maybe it's my phone. all attempts to do backwards result in [ ].
30th May 2021, 2:07 PM
Joel Sebastian Jijo
Joel Sebastian Jijo - avatar