Want to create a python program help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Want to create a python program help

I want to make a program that counts the number of vowels in a given text. The vowels are a, e, i, o, and u. It has to take a string as input and output the number of vowels. Please correct this txt = input() vowels = ['a', 'e', 'i', 'o', 'u'] novowels = 0 for vowels in txt: novowels += 1 print(novowels) How to iterate over the target string char and test for each if is vowel or not

12th Feb 2021, 5:17 AM
Yusuf M Hashmi
Yusuf M Hashmi - avatar
7 Answers
+ 5
for chr in txt: if chr in vowels: novowels += 1
12th Feb 2021, 5:26 AM
visph
visph - avatar
+ 2
where is your attempt? tip: there are many ways to do it... simplest is to iterate over the target string char and test for each if is vowel or not ;)
12th Feb 2021, 5:22 AM
visph
visph - avatar
+ 2
Simba yes, thanks: corrected ^^
12th Feb 2021, 5:40 AM
visph
visph - avatar
+ 1
thanks all
12th Feb 2021, 5:39 AM
Yusuf M Hashmi
Yusuf M Hashmi - avatar
+ 1
"we" have created ^^
12th Feb 2021, 5:46 AM
visph
visph - avatar
12th Feb 2021, 5:45 AM
Yusuf M Hashmi
Yusuf M Hashmi - avatar
0
yes thanks again
12th Feb 2021, 5:47 AM
Yusuf M Hashmi
Yusuf M Hashmi - avatar