研究分配(使用python-3):查找和打印元音
對於學習任務,我需要編寫打印所有元音的指標在一個字符串的程序,最好使用「而循環」。 到目前爲止,我已經成功地設計了一個「for循環」來完成這項工作,但我可以肯定需要在「while循環」
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)
會使用'指數()'或'查找()'在這裏工作?
謝謝掃地!難點在於我還沒有學會如何使用列表,接下來的兩章是元組和列表。我真的仍然很難創造性地使用我們迄今學到的「工具」(這些工具包括:表達式,變量,條件,迭代,函數和當前章節的字符串)但我理解你的解釋,謝謝你的支持幫幫我! – GJ01
@ GJ01我編輯了答案。 *有*解決方法。 – Sweeper
太棒了!非常感謝! :-)你對'元音'和'索引'也是正確的,但我不知道如何返回索引。 – GJ01