【发布时间】:2014-11-23 19:59:02
【问题描述】:
需要在字符串中找到最长的单词并打印该单词。 1.) 要求用户输入以空格分隔的句子。 2.)查找并打印最长的单词。如果两个或多个单词的长度相同,则打印第一个单词。
这是我目前所拥有的
def maxword(splitlist): #sorry, still trying to understand loops
for word in splitlist:
length = len(word)
if ??????
wordlist = input("Enter a sentence: ")
splitlist = wordlist.split()
maxword(splitlist)
在尝试比较句子中单词的长度时,我碰壁了。我是一名已经使用python 5 周的学生。
【问题讨论】:
标签: python python-3.x