【发布时间】:2020-12-23 03:59:05
【问题描述】:
学习作业(使用python 3):
对于一项学习作业,我需要编写一个程序来打印字符串中所有元音的索引,最好使用“while-loop”。 到目前为止,我已经设法设计了一个“for-loop”来完成工作,但我肯定需要一些关于“while-loop”的帮助
for循环解决方案:
string = input( "Typ in a string: " )
vowels = "a", "e", "i", "o", "u"
indices = ""
for i in string:
if i in vowels:
indices += i
print( indices )
while循环解决方案:
string = input( "Typ in a string: " )
vowels = "a", "e", "i", "o", "u"
indices = ""
while i < len( string ):
<code>
i += 1
print( indices )
使用 'index()' 或 'find()' 在这里有用吗?
【问题讨论】:
标签: python-3.x