私は母音の母音を数えたいと思います。しかし、母音の後ろに子音と母音の後ろに母音の数を数えたいと思っています。誰か助けてくれますか?母音の後ろに子音が付いています
これは私がこれまで行ってきたことですが、母音でi + 1を使う行の構文が無効であると言います。
s = "text"
vowels = set("aeuio")
consonants = set("qwrtypsdfghjklzxcvbnm")
vowelcount=0
vowelvowelcount=0
consonantcount=0
consvowelcount=0
consconscount=0
vowelconscount=0
for i in s:
if i in vowels:
vowelcount += 1
if i in consonants:
consonantcount +=1
for i in s:
if (i in vowels,and i+1 in vowels):
vowelvowelcount +=1
print ("number of vowels:", vowelcount)
print ("number of consonants:", consonantcount)
print ("number of vowels followed by vowels:", vowelvowelcount)
文字列スライスを使用して、文字列の途中でカウントしたいと思うでしょう。母音はs [2:3]、母音はs [3:4]のようなものです。 – mba12
@ mba12:でも 's [3:4]'は 's [3]'と同じです... –
@WillemVanOnsem正しいですが、あなたの構文もきれいです。私はあなたの答えを見る前に私のコメントを書いた。 – mba12