Why do I get this EOFError calling raw_input?
Asked Answered
R

1

1

I used an online interpreter to run this code:

print "How old are you?",
age = raw_input()
print "How tall are you?",
height = raw_input()
print "How much do you weigh?",
weight = raw_input()
print "So, you're %r old, %r tall and %r heavy." % (
    age, height, weight)

I get an EOFError on line 2. Why does this happen, and how do I fix it?

Rojas answered 15/4, 2014 at 9:16 Comment(2)
Yeah, online interpreters hardly ever work for that sort of thing. Why don't you just download an IDE?Pisci
Thanks Alex, will do that! I liked the idea of having easy access to the code in the compiler online wherever I go. Guess I can just use Dropbox etc.Rojas
U
4

The problem is that online interpreters usually don’t pause to allow the user to input stuff. Instead, they will use a fixed “file” as stdin from which the data is read. Unless you specify it, it will be empty, so asking for input will result in EOF since the (empty) file was already exhausted.

It is possible to specify the input data though. On ideone, you have to click the stdin button and enter the data at once. For example:

old
tall
weight

Then your script will run.

But you really should consider downloading Python yourself and running it in the command line with a normal interpreter. That way, you actually get some interactivity.

Unsung answered 15/4, 2014 at 9:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.