0

What is the problem of my code? Output comes only blocks

The given code uses an infinite loop to continuously take user input. During each iteration, the user input is added to the items list. Change the code to end the loop when the user enters 0. Output the resulted list after the while loop ends. Sample Input 1 2 3 0 Sample Output [1, 2, 3] My Solution:- items = [] while True: n = int(input()) if(n == 0): break items.append(n) print(items,end=" ")

8th Jan 2021, 9:50 PM
Priyankar Ghosh
Priyankar Ghosh - avatar
5 ответов
+ 2
Priyankar Ghosh EOF means End Of File - a condition that occurs when attempting to read past the end of the available data on an input channel. It is not necessarily related to how code is indented, unless the input statement is wrongly indented into a code block that causes it to request extra data when none is unavailable. In Python, correct indentation is a critical part of the language syntax. It is as important as using consistent spelling of identifier names and keywords and ensuring all parentheses have matching pairs. Be consistent and deliberate with column alignment.
8th Jan 2021, 10:56 PM
Brian
Brian - avatar
+ 2
The requirements say "Output the resulted [sic] list after the while loop ends" but the posted code shows the print statement is inside the loop, according to its indentation. The print statement should not be indented.
8th Jan 2021, 10:07 PM
Brian
Brian - avatar
+ 2
and the statement items.append(n) should be a little bit left. So the right code is: items = [] while True: n = int(input()) if(n == 0): break items.append(n) print(items,end=" ")
8th Jan 2021, 10:23 PM
Zair T
Zair T - avatar
+ 1
Now I get it thanks again Brian 🙂
8th Jan 2021, 10:58 PM
Priyankar Ghosh
Priyankar Ghosh - avatar
0
Заир Теймуров 😅😅I really can't find the difference between ur solution and mine.still ur code works not mine😔. Brian please give me suggestions to over indentation error like EOF error. Thankx to both of you 🙂
8th Jan 2021, 10:41 PM
Priyankar Ghosh
Priyankar Ghosh - avatar