大爽Python入门练习题 1-5 最长字符串
第一章 中期练习题 简单 第5题
题目
简介
实现一个程序,
输入一串用空格分隔的单词(接收用户输入),
输出其中最长的单词。
补充:
只接受一行输入。
默认起码会输入一个单词。
默认除空格外不会有其他符号。
示例
输入示例1:
big shuang python introductory exercise
输出示例2:
introductory
输入示例2:
In the course of this life I have had a great many encounters with a great many people who have been concerned with matters of consequence
输出示例2:
consequence
分割线
本小段没有实际意义,
仅用于分隔题目和答案。
防止学生无意中直接看到答案,
影响思路。
。
。
。
。
。
。
。
。
。
。
。
。
。
。
。
。
。
。
。
。
答案
line = input()
words = line.split()
longest = words[0]
for word in words:
if len(word) > len(longest):
longest = word
print(longest)