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=" ")
5 Answers
+ 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.
+ 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.
+ 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=" ")
+ 1
Now I get it thanks again Brian š
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 š