Home python Why does “EOFError: EOF when reading a line” pop up?

Why does “EOFError: EOF when reading a line” pop up?




pops up an error

Traceback (most recent call last):
  File "script.py", line 2, in <module>
    y1 = int(input())
EOFError: EOF when reading a line

Who will tell you how it should be and why?

Answer 1, authority 100%

EOFErroroccurs when CTRL-D is pressed.

By the way, it is better to do so that the input contains text and you should output not the text “y2”, but the variable y2:

y1 = int(input("Entery1: "))
r = int(input("Enterr: "))
if abs(y1) <= abs(r) and ((y1 > 0 and r < 0) or (y1 < 0 and r > 0)):
    if  r > 0: y2 = y1 + r + 1
elif r < 0:
    y2 = y1 + r - 1
    y2 = y1 + r 

You can also try excepton inputso that only numbers can be entered

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions