python问题求答案啊!急!
PROBLEM: Given a sentence (up to 1024 characters long), output the following:
#1) The number of different letters. This will be a number from 1 to 26, inclusive.
2) The number of vowels. Vowels are the letters a, e, i, o, and u.
3) The number of uppercase letters.
4) The number of times that the most frequent letter appears. There is no distinction between
lowercase and uppercase letters.
5) The longest word in the sentence. If there is a tie, print the one that appears first when sorting
these words alphabetically without regard to lowercase and uppercase.
INPUT: One line of data, containing a sentence, up to 1024 characters long.
OUTPUT: Print the five statistics specified above in that order.
SAMPLE INPUT
The quick brown fox, named Roxanne, jumped over Bruno, a lazy dog.
SAMPLE OUTPUT
#1. 25
2. 19
3. 3
4. 6
5. Roxanne

python问题求答案啊!急!
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
4条回答 默认 最新
关注
# 获取全部不同的字母个数 def get_diff_letter(input_str): return len(set(list(filter(str.isalpha, input_str)))) # 获取元音字母次数 def get_num_of_vowel(input_str): print(sum([1 for letter in input_str if letter.lower() in ['a', 'e', 'i', 'o', 'u']])) # 大写字母开头的单词个数 def num_of_upper(input_str): print(sum([1 for letter in input_str if letter.isupper()])) # 出现次数最多的字母 def word_of_freq(input_str): most_freq = 0 for letter in input_str: num_letter = input_str.count(letter) most_freq = max(most_freq, num_letter) print(most_freq) # 最长的单词 def longest(input_str): input_str = input_str.replace(',', '').replace('.', '') # 过滤掉英文逗号和句号 words = input_str.split(' ') print(max(words, key=len)) if __name__ == '__main__': input_str = 'The quick brown fox, named Roxanne, jumped over Bruno, a lazy dog.' get_diff_letter(input_str) get_num_of_vowel(input_str) num_of_upper(input_str) word_of_freq(input_str) longest(input_str)
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录