辅音和元音字母数

要求:

编写一个程序来计算给定单词中辅音字母和元音字母的数量。

  • 定义函数count_consonants(),参数为word。该函数应返回单词中辅音字母的数量。
  • 定义函数count_vowels(),参数为word。该函数应返回单词中元音字母的数量。

示例输入

Programming

示例输出

8

3

  • 忽略数字,特殊字符和空格。
  • 元音字母为: aeiou

代码:

ss = "aeiou"
s = "bcdfghjklmnpqrstvwxyz"

def count_consonants(word):
    count1 = 0
    str1 = word.lower()
    for s1 in str1:
        if s1 in s:
            count1+=1
    return count1

def count_vowels(word):
    count2 = 0
    str2 = word.lower()
    for s2 in str2:
        if s2 in ss:
            count2+=1
    return count2

# 获取用户输入
word = input()

# 调用函数
print(count_consonants(word))
print(count_vowels(word))

 注意:

for  和 if  后面参数填写不正确,会导致结果不对

主要还是逻辑问题会导致出现上面的错误

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值