【发布时间】:2023-02-21 11:24:30
【问题描述】:
您好,我需要帮助计算给定 book_excerpt 中以字母“a”开头的单词数量,我们存储在 num_with_a 和“d”中,我们存储在 num_with_d 中。
book_excerpt = "It was both the greatest and worst of times; it was the Age of Wisdom and the Age of Folly; it was the Epoch of Belief and the Epoch of Skepticism; it was the Age of Light and the Age of Darkness; it was the Spring of Hope and the Winter of Despair."
这是我试过的:
num_with_a = for f in book_excerpt:
if beginning 'a' in f:
print(f)
num_with_d = for f in book_excerpt:
if beginning 'd' in f:
print(f)
【问题讨论】:
-
好吧……怎么了?大概你有一个
SyntaxError? (您是否还尝试过任何 Python 入门教程,例如 the official one?)顺便说一句,欢迎来到 Stack Overflow。首先检查的好地方是tour、How to Ask和minimal reproducible example。
标签: python