为什么我的用于识别文本中元音的命令块没有显示?

问题描述 投票:0回答:1
text = """
Inserting comments into program code is normal practice.
As a result, every programming language has some way of allowing comments to be inserted into programs.
The objective is to add descriptions to parts of the code, either to document it or to add a description of the implemented algorithm."
"""

vowel = 'a' or 'e'
for i, vowel in enumerate(text):
    if vowel == text:
       print(f"Vowel {vowel} found in position {i}")
    else:
       continue

我正在尝试创建这个块,它应该显示找到哪个元音及其在文本中的位置,但是,当我运行程序时,它不会执行任何操作。 我最近开始尝试理解为什么它不起作用......

python loops for-loop enumerate
1个回答
0
投票
text = """
Inserting comments into program code is normal practice.
As a result, every programming language has some way of allowing comments to be inserted into programs.
The objective is to add descriptions to parts of the code, either to document it or to add a description of the implemented algorithm."
"""

# iterable of vowels
vowels = 'aeiou'

# for every character in the text
for i, char in enumerate(text):

    # report if character is in vowels
    if char in vowels:
        print(f"Vowel {char} found at position {i}")
© www.soinside.com 2019 - 2024. All rights reserved.