Sang
Sang

Reputation: 11

while loop until empty string in online interpreter

Why does my program work in PyCharm but in online interpreter gives this error:

Traceback (most recent call last): File "Solution.py", line 4, in s = input() EOFError: EOF when reading a line

Here's the part of code that matters:

i = 0
while True:
    s = input()
    if s == '':
        break
    else:
        ...

I'm trying to input strings until empty string occurs but it always gets stuck on line with empty string. Thanks in advance and sorry if I'm sloppy with my question (my 1st question).

Upvotes: 0

Views: 1380

Answers (1)

user11553043
user11553043

Reputation:

Perhaps you can handle there exception with try and except:

while True:
    try:
        s = input()
        ...
    except EOFError:
        break
...

Upvotes: 0

Related Questions