Hello, I'm a starter in Python and I need help. I'm trying to ask the user to input as much text as he/she likes until he/she types EOF (end of file) on a separate line. Once he/she does, the program should end. I started on my code and below is what I have so far. I'm using the 'for' loop in my code, is that correct?

#Set textInput to 0?
textInput = 0
    #Use the 'for' loop to keep looping.
    for i in textInput:
        #Prompt for user text input. Is this in the right spot?
        textInput = input()
        #If the user types EOF on a new line, then end the program.
        if textInput == "\n" and textInput == "EOF":
            break
        #Keep going until EOF is typed. Is this right?
        else:
            continue

"EOF" means three letters: E,O,F.
This statement is never True:
if textInput == "\n" and textInput == "EOF":

One way to handle this ("\n" cannot be entered) is to catch EOFError:

inputs=list()
while True:
    try:
        s = input()
        inputs.append(s)
    except EOFError:
        print(inputs)
        break
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.