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
Re: Python: How to ask user for text input? 80 80

"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 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.