题解 | #计算某字符出现次数#
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
#输入字符串 a = input("") if len(a) < 1 or len(a) > 1000: print("总字符请控制在1-1000以内") #输入查询字符 standard = input("") a = a.lower() standard = standard.lower() count = 0 for c in a: if c == standard: count += 1 print(f"{count}")
获取两个input,然后为两个input的variable统一转化为小写确保可以被查询时正确count。for循环每个a当中的char,如果char与查询字符相等则+1。最后print count结束