我试图提示用户输入一段文本,直到他/她在单独的行上单独键入 EOF。之后,程序应该为他/她提供一个菜单。当我转到选项 1 时,它只打印出 EOF,而不是之前输入的所有内容。为什么是这样?
假设我输入“嗨,我喜欢馅饼”作为我的文本块。我输入 EOF 进入菜单并输入选项 1。我希望“嗨,我喜欢馅饼”会弹出,但只有字母 EOF 会弹出。我该如何解决?我如何“喂”一个 Python 文件?
#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)