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 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
程序员星辰 2023-02-08 11:10关注以下为代码,有用点采纳
sentence = input().strip() letters = {} vowels = 0 uppercase = 0 longest_word = "" for char in sentence: if char.isalpha(): if char.lower() in letters: letters[char.lower()] += 1 else: letters[char.lower()] = 1 if char.lower() in "aeiou": vowels += 1 if char.isupper(): uppercase += 1 words = sentence.split() for word in words: if len(word) > len(longest_word): longest_word = word elif len(word) == len(longest_word) and word < longest_word: longest_word = word print("#1.", len(letters)) print("2. ", vowels) print("3. ", uppercase) print("4. ", max(letters.values())) print("5. ", longest_word)解决 无用评论 打赏 举报