r/learnpython • u/Fakishaccount • 32m ago
EOF when writing code for list
I appreciate the help I get on here, and I have an issue I was not taught of to fix. When I write the following code I get an error saying "EOF when reading a line" and I really dont know why. This is the code:
num_raw = int(input())
raw_list = []
i = 0
while i <= (num_raw - 1):
raw = input()
raw_list.append(raw)
i = i +1
print(raw_list)
The task says that the first input would follow how many inputs come next, and then to make a list.
I would assume the raw variable would become the input and then add the variable to the list, and do this as many times that exist from the first input. But no matter how I write it "raw = input()" comes up with EOF. Can someone tell me what i am missing?
please and thank you
•
•
u/atarivcs 22m ago
Does the EOF error come up right away, even before the first input?
Or does it accept some inputs, and then the EOF error comes up later?
Also as a side comment, if you want a loop that runs a specific number of times, it's simpler and more idiomatic to use for-range instead of while:
for i in range(num_raw):
...This way avoids a lot of little headaches:
initializing i to the right value (should it be zero or one?)
using the correct end value (should it be end or end-1?)
using the correct comparison (should it be less-than, or less-than-or-equal?)
•
u/cdcformatc 10m ago
how are you running this? are you running it by piping from another process?
for example echo "1 2" | test.py will throw this sort of error.
•
u/carcigenicate Carcigenicate 2m ago
When an EOF error is raised by input, that means the input data was presupplied, and you're asking for more input data than was provided.
If this is on an online environment:
If you're being tested, your program is broken and is asking for more input than was intended.
If you're just dicking around on your own, the site should have an input box somewhere where you can provide the input that will get plugged in.
•
u/mopslik 29m ago
Assuming your code is written as follows:
Then I get the following output for my input:
Seems to work fine for me. Maybe an issue with your environment? Or did you enter a blank input?