+ 16

It says the answer is 4, but if nums=list (range (5)) then if I print (nums) I should see 0,1,2,3,4. and if I then print nums but indexing 4 it should be printing 3. what am I missing?

22nd Jun 2016, 5:44 AM
zak
zak - avatar
12 ответов
+ 8
indexing is start from 0 not 1
22nd Jun 2016, 7:04 AM
Rudi
Rudi - avatar
+ 8
But in the explanation there is an example: range(10) gives [0,1,2...,8,9]. That is, 10 figures. So range(5) should result in [0,1,2,3,4], isn'it?
2nd Jul 2016, 10:21 PM
Alf
+ 4
It goes from zero to 5, not 4. So there are 6 numbers in the list. It is therefore confusing. So, the list created is - [0,1,2,3,4,5]. Other confusing part is that it doesn't ask for 4th number in the list, which would be - 3, but rather 4th index. In this case 4th index is 5th element in the list, number 4. All the confusion stems from the fact that Python indexing begins with zero.
24th Jun 2016, 6:36 PM
Si-Wei Duo
+ 1
yes as by example answer should be 3
5th Aug 2016, 8:30 AM
Han Sol Jung
Han Sol Jung - avatar
+ 1
The range function lists numbers [0,1,2,3,4] and assigns it to 'list'. When list[4] is printed, indexing starts from 0 and hence 4th element is the '3'. and not '4'. It's not taking it as the answer. Am I missing something?
13th Sep 2016, 9:27 AM
Nischith P Javagal
Nischith P Javagal - avatar
+ 1
list1 = range(5) is [0,1,2,3,4] and list2 = range(10) is [0,1,2,3,4,5,6,7,8,9] according to the provided example. So, why does list1 index[4] not result in the answer 3?
2nd Nov 2016, 9:15 PM
johnathen
+ 1
0th index iz zero, 1st index is 1, 2nd index is 2... and goes on. so answer is 4. you can try it. define a list and print
18th Feb 2017, 11:53 AM
Tuna ASLAN
Tuna ASLAN - avatar
0
I've got the same question. in my opinion the output for this example would be 3 according to the examples provided
7th Jan 2017, 6:30 PM
Marta A
Marta A - avatar
0
I think it should be 3 the right answer.
16th Jan 2017, 10:43 AM
Marco C.
0
it is right when it's says 4 for the index it calls variables 0-4 which is 4
22nd Feb 2017, 6:48 PM
Justin Wright
Justin Wright - avatar
0
hasil nya 2 bro
3rd May 2017, 6:36 AM
Ardin.S
Ardin.S - avatar
0
I'm not sure, but the count of the function always starts at 0, but the lists start at 1 or at 0, for this case it started at 0, but in the previous quiz it started at 1, so our count was subtracted 1 with respect to the list
23rd Oct 2018, 2:46 AM
Antonio Ali Cardoza