Why does this code still print the zero (0)? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why does this code still print the zero (0)?

items = [] n = 0 while True: n = int(input()) items.append(n) if(n == 0): break print(items)

28th Nov 2020, 8:02 AM
IronChancellor
IronChancellor - avatar
2 Answers
+ 8
This is because you are checking the value of "n" after inserting it into the list.
28th Nov 2020, 8:04 AM
Arsenic
Arsenic - avatar
+ 1
Thank you!
28th Nov 2020, 12:29 PM
IronChancellor
IronChancellor - avatar