2. 完成字符串“吃葡萄不吐葡萄皮,不吃葡萄到吐葡萄皮”中“葡”字的个数,以count.py保存。
时间: 2024-05-27 07:13:48 浏览: 85
计算字符串中字符个数
count = 0
str = "吃葡萄不吐葡萄皮,不吃葡萄到吐葡萄皮"
for i in str:
if i == "葡":
count += 1
with open("count.py", "w") as f:
f.write("count = {}".format(count))
阅读全文