我試圖提示用戶輸入一段文字,直到他/她自己在單獨一行中鍵入EOF。之後,程序應該向他/她提供一個菜單。當我進入選項1時,它僅打印出EOF,而不是之前輸入的所有內容。爲什麼是這樣?Python:如何將用戶文本輸入存儲在文件中?
假設我輸入「Hi I like pie」作爲我的文本塊。我輸入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)
謝謝您的快速響應先生。 – user2581724
沒問題!希望能幫助到你! – jh314