写出一个程序,接受一个由字母、数字和空格组成的字符串,和一个字符,然后输出输入字符串中该字符的出现次数。(不区分大小写字母)
数据范围:
def string_count(str, char): a = str b = char map = {} for i in range(len(a)): if a[i].lower() not in map: map[a[i].lower()] = 1 else: map[a[i].lower()] += 1 if b.lower() not in map: return 0 else: return map[b.lower()] while True: try: str = input() char = input() print(string_count(str, char)) except EOFError: break
def count(s,c): j=0 for i in range(len(s)): if c==s[i]: j+=1 return j #print('enter string:') s=input().lower() #print('enter a char') c=input().lower() r=count(s,c) print(r)