Python编程PTA题解大全——索引
Description:英文辅音字母是除A、E、I、O、U以外的字母。本题要求编写程序,统计给定字符串中大写辅音字母的个数。
Input:输入仅一行,输入一个不超过80个字符、并以回车结束的字符串。
Output:输出仅一行,输出字符串中大写辅音字母的个数。
Sample Input:HELLO World!
Sample Output:4
str = input()
yuanyin = ['a', 'e', 'i', 'o', 'u'] #元音字母
num = 0
for ch in str:
if ch.lower() not in yuanyin and ord('A') <= ord(ch) <= ord('Z'): #不是元音并且是大写
num += 1
print(num)