You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi Damian,
When you feed input to the Python interpreter, use the EOF symbol CTRL+D
(on Windows) or CTRL+Z? (on Linux/Mac - I am not sure) after the last line
of input.
Because
inputs = iter(sys.stdin.readlines())
reads all input at one go.
Alternatively, use command line IO redirection like this
On Tue, Dec 29, 2020 at 1:04 PM Damian Mingle ***@***.***> wrote:
I tried to run this code and received a StopIteration error.
# IO_in1.txt
import sys
inputs = iter(sys.stdin.readlines())
TC = int(next(inputs))
for _ in range(TC):
print(sum(map(int, next(inputs).split())))
Can you tell me how to prevent this traceback?
---------------------------------------------------------------------------
StopIteration Traceback (most recent call last)
<ipython-input-221-4615b4523133> in <module>
1 import sys
2 inputs = iter(sys.stdin.readlines())
----> 3 TC = int(next(inputs))
4 for _ in range(TC):
5 print(sum(map(int, next(inputs).split())))
StopIteration:
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#83>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABIDWOEP4P6HQYNJCS22LE3SXFPMTANCNFSM4VMZSJPA>
.
I tried to run this code and received a StopIteration error.
Can you tell me how to prevent this traceback?
The text was updated successfully, but these errors were encountered: