Vocal and consonant in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Vocal and consonant in python

how to know this input AlohaNamaSayaBudi and the output is 9 8 9 is vocal 8 is consonant well how to know many vocal and consonant with python code with beginner code and explanation

15th Oct 2017, 5:47 PM
Jansen Su
Jansen Su - avatar
4 Answers
+ 11
# Just use "Copy text" and paste it into Python CodePlayground # If you want to do it the smartest way - import re and find and match vowels and consonants. # However, you may also create a vowels list by hand (as it's shorter than consonants ;) and iterate through the given string adding 1 whenever the currently iterated element is in the vowels list. # Like this: vowels = 'aeiou' # 'y' is iffy in English ;) s = 'AlohaNamaSayaBudi' v = 0 # v will act as a vowel counter for ch in s: # iterating through the string if ch.lower() in vowels: v += 1 # increase v by one if a vowel is spotted print('{} has {} vowels and {} consonants.'.format(s, v, len(s)-v)) # prints the string, the vowels and the number equal to length minus vowels (assuming there are no spaces or special characters)
15th Oct 2017, 6:33 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 10
@Ace Very True, but it came to me unexpectedly on an English test ;) Had never really thought about it and I assumed of course it's a vowel, just like in Polish. Zonk! Nope. :)
15th Oct 2017, 6:41 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 5
By vocal, I think you mean vowel. vowel = 0 consonant = 0 for letter in 'AlohaNamaSayaBudi'.lower(): if letter in 'aeiou': vowel += 1 else: consonant += 1 print(vowel) print(consonant)
15th Oct 2017, 6:26 PM
ChaoticDawg
ChaoticDawg - avatar
0
waw Thanks @ChaoticDawg @Ace @Kuba SiemierzyƄski i will try all your code
16th Oct 2017, 3:41 AM
Jansen Su
Jansen Su - avatar