在一行上输入若干个字符串,每个字符串代表一个单词,组成给定的句子。
除此之外,保证每个单词非空,由大小写字母混合构成,且总字符长度不超过
。
在一行上输出一个整数,代表最后一个单词的长度。
HelloNowcoder
13
在这个样例中,最后一个单词是
,长度为
。
A B C D
1
str=input() temp=str.split(".") s=float("0."+temp[1]) if s>=0.5: print(int(temp[0])+1) else: print(int(temp[0]))
import sys for line in sys.stdin: a = line.split() print(len(a[-1]))
while True: # 写代码前记得加限定条件 try: in_str = input() if len(in_str) > 5000&nbs***bsp;len(in_str) == 0: raise Exception last = in_str.strip().split(" ")[-1] leng = len(last) print(leng) break except Exception: print("The length of str is invalid, please input it again!")