1234ty

# 统计如下字符串中,有多少个字母a
name = "I am a happy person and I enjoy eating apples"

# 定义一个变量,用来统计有多少个a
count = 0

# for 循环统计
# for 临时变量 in 被统计的数据:
for x in name:
    if x == "a":
        count += 1

print(f"{name}中共有{count}个a")
posted @ 2023-07-07 09:35  嘲讽二百五的五百五  阅读(57)  评论(0)    收藏  举报