Hi, I'm trying to prompt the user to enter a block of text until he/she types EOF on a separate line by itself. After that, the program should present him/her with a menu. When I go to Option 1, it only prints out EOF and not everything that was typed earlier. Why is this?

Let's say I type "Hi I like pie" as my block of text. I type EOF to head to the menu and type option 1. I expect "Hi I like pie" to pop up but only the letters EOF does. How do I fix this?

#Prompt the user to enter a block of text.
done = False
while(done == False):
    textInput = input()
    if textInput == "EOF":
        break

#Prompt the user to select an option from the Text Analyzer Menu.
print("Welcome to the Text Analyzer Menu! Select an option by typing a number"
    "\n1. shortest word"
    "\n2. longest word"
    "\n3. most common word"
    "\n4. left-column secret message!"
    "\n5. fifth-words secret message!"
    "\n6. word count"
    "\n7. quit")

option = 0

while option !=7:
    option = int(input())

    if option == 1:
        print(textInput)

You are continually replacing the value of textInput using that loop. Try creating a list element and append to it instead.

Something along the lines of this perhaps?...

done = False
textInput = []
while(done == False):
    temp = input()
    if temp == "EOF":
        break
    else:
        textInput.append(temp)

can concatenate/format the output easily several ways and can use built-in list functions for your counting needs.

Edited 3 Years Ago by PsychicTide

This question has already been answered. Start a new discussion instead.