Sal's Shipping -- input statement gives EOF error?

Running into a strange input statement error with my code for this project

Steps to reproduce:

  1. With the entire code window blank, I type this line of code:
    pkg_weight = float(input("Enter the weight: "))

  2. Click Save.

In the results window, this displays immediately:

Enter the weight: Traceback (most recent call last):
File “script.py”, line 38, in
pkg_weight = float(input("Enter the weight: "))
EOFError: EOF when reading a line

Any ideas?

MacBook Pro running Catalina 10.15.3 / Firefox 74.0

2 Likes

Hi there, welcome to the forum!

I think that the reason you’re getting the error is because the “terminal”, in that exercise anyway, is not configured to accept input. So, when you’re trying to get input from the user - which, in the real world would be a totally normal and expected thing to do - the terminal area can’t handle that, so it tries to just carry on and you’re getting the EOF error.

I suspect that, for the purposes of that project, you’re meant to pass the values for weight etc directly into your function calls rather than getting a value via input in the terminal. :slight_smile:

1 Like

That makes a lot of sense - thanks!

I used the input statement because the instructions for that section said to “ask the user for the package weight.” The rest of my code worked just fine after dropping the input statement, but I wanted to make sure I wasn’t missing something obvious.

Thanks for your reply!

2 Likes

Thanks for letting us know ! I was wondering why I couldn’t get my input to work :tired_face: . Also what does EOF stand for?

1 Like

I’m glad we found an answer. It was driving me nuts!!

EOF is short for “End Of File”. My guess is that when the terminal tries to handle keyboard input and fails, the closest thing it can come up with is “dang, I hit the end of the file that you’re trying to read”, thus the EOF error. Perhaps it sees user input as a form of file input?

Mark it down as “yeah, whatever” and go on. :slight_smile:

2 Likes

Pretty much.

https://docs.python.org/3.9/library/exceptions.html#EOFError

The instructions should be changed.

I used the input statement because the instructions for that section said to “ask the user for the package weight.”