# Why the output is 9 ......

#this code giving me indentation error on print statement please solve this and tell me why the output is 9 a=[1,2,3,4,12,13] for i in a: if i%2==1: a.append(0) Print (len(a))

7/9/2020 7:07:49 PM

Akash Gupta56 Answers

New AnswerAkash Gupta length is 9 because we are appending in original array. Explaination: a = [1, 2, 3, 4, 12, 13] According to condition 1 % 2 == 1 //true Now a will be a [1, 2, 3, 4, 12, 13, 0] 3 % 2 == 1 //true Now a will be a [1, 2, 3, 4, 12, 13, 0, 0] 13 % 2 == 1 //true Now a will be a [1, 2, 3, 4, 12, 13, 0, 0, 0] Finally length will be 9 see here.. https://code.sololearn.com/cGydxwaIInsV/?ref=app

To add to Abhay 's answer: for the output to just be 9, the if should be if i%2 != 0, and print should be de-indented. Length of a starts out at 6 and, for every odd number (assuming the 'if' is amended as above), a 0 is added to it. As this happens 3 times, len(a) is 9 at the end.

It doesn't gives any indentation errors ,perhaps the error maybe about print since it is lowercase not uppercase Also the output is 6 7 7 8 9 9 10 11 12 . . infinite Which is right.

Akash Gupta According to your code you are printing the length inside loop that's why you are getting output like that.

Ishu Kumar There is no difference. No need to update question. In description he also mentioned why the output 9.

Akash Gupta Please double check the code in the challenge. This code will not give 9. If this is what the code says, report question for having wrong answer.

I believe the correct answer is AJ Anant . If its remainder 1(odd number), append 0 to the original list (not the number). From the list 3 of the numbers are odd so three zeros are added to the original list. Length of list would be 9 not infinity. Would only be infinity if the original numbers which are odd are added back.

Be cause you are printing length of the list and also appending 0 when the elements of the list give a remainder of 1 when divided by 2 . And there are three cases when the remainder is 1 when the elements of the list is divided by 2 i.e. 1, 3, 13 . That's why 0 has been appended 3 times in ur list and ur resultant list looks like [1,2,3,4,12,13,0,0,0] You can easily count that there are 9 elements in the list . That's why the result is 9 . Hoping that u will understand . If the issue remains unsolved kindly message me .

𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 this question is in the challenge ....and opponent mark the option which is 9

Akash Gupta Post the picture on your own feed, then copy the link for your post into this thread

𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 sorry bro my mistake and sry for wasting your time ... please explain it