プログラムでテキスト ファイルから 5 単語ごとに取得し、それを 1 つの文字列に配置しようとしています。たとえば、「パイはおいしくて、ブルーベリー ストロベリーやライムなど、さまざまな種類があるので、誰もがパイを食べるのが好きです」と入力した場合、プログラムは「Everyone because plus types and.」と出力するはずです。最初の単語から始めて、5 番目の単語ごとに取得する必要があります。これを行う方法について混乱しています。以下は私のコードです。最後の5行を除いてすべて正常に動作します。
#Prompt the user to enter a block of text.
done = False
textInput = ""
while(done == False):
nextInput= input()
if nextInput== "EOF":
break
else:
textInput += nextInput
#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")
#Set option to 0.
option = 0
#Use the 'while' to keep looping until the user types in Option 7.
while option !=7:
option = int(input())
#I'm confused here. This is where I'm stuck. Is the 'for' loop correct for this `#situation?`
#If the user selects Option 5,
elif option == 5:
for i in textInput.split():
if i <= 4 and i >= 6:
print(textInput)