r/learnpython • u/Fakishaccount • 12m 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/mopslik 8m 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?
•
u/Rudeus_Kino 7m ago
Look at the file, how many lines?
•
u/lfdfq 7m ago
Error from where? You said, "The task", is it possible you are misinterpreting what it is asking for?
•
u/atarivcs 2m 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:
This way avoids a lot of little headaches: