这个程序怎么编写呢?用C和python写一下

问题遇到的现象和发生背景

Write a function, in C or Python, that returns the number of lowercase letters in a chain of characters passed as a parameter. For example, if the chain is Semi-annual, the function must return the number 9.

问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果

解答如下

img

#include <stdio.h>
#include <string.h>
int Count_lowercase_letters(char str[])
{
    int count=0,i;
    for(i=0;i<strlen(str);i++)
    {
        if(str[i]<='z'&&str[i]>='a')
        {
            count++;
        }
    }
    return count;
}

int main()
{
    char str[150];
    gets(str);
    printf("The number of lowercase letters:%d\n",Count_lowercase_letters(str));
    return 0;
}
s='Semi-annual'
n=0
for i in s:
    if 'a'<=i<='z':
        n+=1
print(n)

用python的话可以使用正则替换,然后统计剩余字符数

import re
s = 'Semi-annual'
print(len(re.sub('[^a-z]+','',s)))

没理解错的话,这道题是要编写一个函数实现对输入字符串中的小写字母进行统计把,C代码如下:

#include<stdio.h>
#include<string.h>
int fun(char s[],int n)
{
    int count = 0;
    for (int i = 0; i < n; i++)
        if (s[i] >= 'a' && s[i] <= 'z')
            count++;
    return count;
}
int main()
{
    char s[100] = {'\0'};
    int len, result;
    gets(s);  //输入字符串
    len = strlen(s);  //计算字符串长度
    result = fun(s,len);  //调用函数,将结果传给result
    printf("%d\n", result);//输出字符串中小写字母个数
}