+ 2

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.

31st Dec 2017, 6:24 AM
GGamer
5 Respuestas
+ 4
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.
31st Dec 2017, 7:50 AM
blackcat1111
blackcat1111 - avatar
+ 3
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.
31st Dec 2017, 6:33 AM
Sebastián Zapata
Sebastián Zapata - avatar
+ 2
hm... report the question with "wrong answer"
31st Dec 2017, 6:36 AM
LunarCoffee
LunarCoffee - avatar
+ 1
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
31st Dec 2017, 12:09 PM
M S Pawan Ranjith
0
Yeah... I was sure it was square brackets, but I must have been mistaken.
31st Dec 2017, 4:22 PM
GGamer