0
why is nums = list(range (5,8) print (Len(nums)) = 3 isn't 4?
13 Respostas
+ 6
It's 3 because your asking for a list with a range from 5-8. Remember that with a list [0] is really the first thing in the list.
Try printing 'nums' and you will see the list:
[5, 6, 7]
Your brain wants to think that it's 6, 7, 8 though. Either way, the length between 5 and 8 is three numbers.
+ 3
in range(a, b) b is not counted by python soin range(5, 8) elements will be 5, 6, 7 so len is 3
+ 1
3
0
yup. when it's range (1, 5) it will not count the top number, or 5 in this case.
0
thanks for answering appreciated
0
see when the range is 1 to 5 then the IDLE shows numbers upto 5 which are 1,2,3,4
0
5
0
The ans is 3
0
And:3
0
the answer is
3
0
3
0
len is 3
0
3