题解 | #计算某字符出现次数#
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
def count_char_occurrences(string, char):
# 将字符串和字符都转换为小写,以便不区分大小写
string = string.lower()
char = char.lower()
# 使用 count() 方法计算字符在字符串中出现的次数,并返回结果
return string.count(char)
while True:
try:
# 逐行读取输入
input_string = input().strip()
char_to_count = input().strip()
# 调用函数计算字符在字符串中出现的次数,并输出结果
print(count_char_occurrences(input_string, char_to_count))
except EOFError:
break
百度公司氛围 554人发布
