寻求帮助
sentence = "python is a high level general purpose programming
language that can be applied to many different classes of problems."
num_a_or_e = 0
for i in sentence:
if i ==['a'] or i == ['e']:
num_a_or_e += 1
print(num_a_or_e)
发布于 2019-04-21 06:58:21
你需要检查收容。你可以做到in
。此外,您需要迭代单词。对于这个例子,.split()
应该给你单词(它由白色空格夹板)。
sentence = '''python is a high level general purpose programming language that can be applied to many different classes of problems.'''
num_a_or_e = 0
for i in sentence.split():
if ('a' in i) or ('e' in i):
num_a_or_e += 1
print(num_a_or_e)
发布于 2019-04-21 07:59:45
试试这个代码
import re
sentence = " the following example"
list =re.findall("[ae]\w", sentence)
print(list)
https://stackoverflow.com/questions/-100006648
复制相似问题