Я пытаюсь заставить свою программу распечатать самое короткое и самое длинное слово, найденное в текстовом файле. Допустим, я набираю «Пирог вкусный» в качестве блока текста. Затем я набираю EOF в отдельной строке, чтобы завершить фазу ввода. Я набрал вариант 1, чтобы увидеть самое короткое слово, и «is» должно появиться, но я получаю только букву «p» в качестве вывода. Я получаю тот же результат для второго варианта, который находит самое длинное слово, я получаю букву «р», когда она должна быть «вкусной». Кстати, для этого я использую функцию min и max.
#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())
#Print out the shortest word found in the text.
if option == 1:
print(min(textInput, key = len))
#Print out the longest word found in the text.
elif option == 2:
print(max(textInput, key = len))