Funny Quiz Questions | Sololearn: Learn to code for FREE!


Funny Quiz Questions

I was taking a Python quiz, and I came upon this question: ‘What is the output of this code? ppap = [“pen”, “pineapple”, “apple”, “pen”] print(len(ppap)) The answer was not 4.

12/31/2017 6:24:30 AM


5 Answers

New Answer


Adding on to what @Sebastián Zapata said; There is no error with the question. However, I notice you have made a mistake while writing the question; this is the corrected question: ppap = {"pen", "pineapple", "apple", "pen"} #Note the curly brackets print(len(ppap)) As ppap is a set, it does not accept repeated values. (So the second "pen" is omitted). Hence the length is 3. If it were square brackets "[]" and not curly ones (like your original question), it would be 4.


Maybe there was a detail that you didn't see. The result of that is really 4. If you use set: " { } ", the result is 3 because it doesn't accept repetitions. But in lists " [ ] ", as you writed the quiz the answer must be 4.


hm... report the question with "wrong answer"


if ur question over here is exactly the same u had then, 4 is the length. but if it's { } it's considered as set, and set doesn't allow repetition so 'pen' is taken as one and length is 3


Yeah... I was sure it was square brackets, but I must have been mistaken.