有沒有辦法編輯這個程序,以便它返回列表中具有給定元音數(shù)量的單詞數(shù)?我試過了,但似乎無法返回正確的數(shù)字,而且我不知道我的代碼輸出的是什么。(我是初學者)def getNumWordsWithNVowels(wordList, num):totwrd=0x=0ndx=0while ndx<len(wordList): for i in wordList[ndx]: if(i=='a' or i=='e' or i=='i' or i=='o' or i=='u' or i=='A' or i=='E' or i=='I' or i=='O' or i=='U'): x+=1 if x==num: totwrd+=1 ndx+=1return totwrd打印(getNumWordsWithNVowels(aList,2))這輸出“2”,但它應(yīng)該輸出“5”。
返回具有給定元音數(shù)量的列表中的單詞數(shù)
慕無忌1623718
2021-11-09 16:21:48