我开始学习 python,并且到目前为止编写了一个程序,允许用户输入一系列文本行,然后输出最长行的字符数。你能告诉我我需要添加什么来显示最长的文本本身和字符数吗? 谢谢。
print('Please enter lines of text.')
print('Finish with a blank line.')
maxi = 0
text = '.'
while len(text) > 0:
text = input()
if len(text) > maxi:
maxi = len(text)
if maxi == 0:
print('No text entered.')
else:
print('The longest line of text was ' + str(maxi) + ' characters long.')
请您参考如下方法:
你必须像这样保存最大长度的文本:
print('Please enter lines of text.')
print('Finish with a blank line.')
maxi = 0
maxiText = ''
text = '.'
while len(text) > 0:
text = input()
if len(text) > maxi:
maxi = len(text)
maxiText = text
if maxi == 0:
print('No text entered.')
else:
print('The longest line of text was ' + str(maxi) + ' characters long. The text is ' + maxiText)
