题解 | #计算某字符出现次数#
计算某字符出现次数
http://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
Python 3 解题思路:
首先第 1步:创建两个输入
str_1 = input("Pls type in a string including space, number and charachter.") str_2 = input("Pls type in one string.")
a = str_1.lower() b = str_2.lower()
用 n 作为计数工具,最后输出 n
n = 0 for i in a: if i == b: n = n +1 print(n)
另外,我一开始本来想增加一步判定 str_1 是不是 字母 + 数字 + 空格 的组合,但是没找到合适的方法和函数…… 哪位大神会的话求指教!