【问题描述】
要求:输入任意字符串,统计其中元音字母('A','E','I', 'O', 'U',不区分大小写)出现的次数和比例(占总字符数中的比例)
思路:对字符串统一大小写后统计其中的元音个数
【样例输入】
FUZHOU -- More than 300 museums, including the national Museum of China and the Palace Museum, are taking part in a biennial museum expo in China.
【样例输出】
A:13,8.90%
E:11,7.53%
1:10,6.85%
0:5,3.42%
U:11,7.53%
【样例说明】
输入的字符串总字符包括标点符号,空白字符等
输出的结果分5行,每一行分别显示AEIOU五个元音的情况,元音后的冒号与逗号两边没有空格,百分比显示小数点后2位
words = 'FUZHOU -- More than 300 museums, including the national Museum of China and the Palace Museum, are taking part in a biennial museum expo in China.'
chars = ('A','E','I','O','U')
for c in chars:
n = words.upper().count(c)
print(f'{c}:{n},{n/len(words):.2%}')
'''
输出:
A:13,8.90%
E:11,7.53%
I:10,6.85%
O:5,3.42%
U:11,7.53%
'''