# -*- coding: utf-8 -*-
"""
Created on Sat Oct 19 11:42:25 2019
@author: shark
"""
print("This code should compute the number of vowels in a string.")
input_string = input( "Enter a string (e.g. your name): " )
a = "a"
A = "A"
e = "e"
E = "E"
i = "i"
I = "I"
o = "o"
O = "O"
u = "u"
U = "U"
acount = 0
ecount = 0
icount = 0
ocount = 0
ucount = 0
Acount = 0
Ecount = 0
Icount = 0
Ocount = 0
Ucount = 0
if a in input_string :
acount = acount + 1
if A in input_string :
Acount = Acount + 1
if e in input_string:
ecount = ecount + 1
if E in input_string :
Ecount = Ecount + 1
if i in input_string :
icount = icount + 1
if I in input_string :
Icount = Icount + 1
if o in input_string :
ocount = ocount + 1
if O in input_string :
Ocount = Ocount + 1
if u in input_string :
ucount = ucount + 1
if U in input_string :
Ucount = Ucount + 1
number_of_vowels = acount+ecount+icount+ocount+ucount+Acount+Ecount+Icount+Ocount+Ucount
print( "The number of vowels in the string is:", number_of_vowels )
(a) Total number of vowel occurences in a string
To answer this question, you need to write code that will calculate the number of vowels in a string. You should count each occurrence of any vowel and count vowels both in upper and lower case, so a vowel is any of the letters in the string: aeiouAEIOU. (Do not count "y", though it may be used as a vowel, e.g. in "my".)
Examples | |
---|---|
INPUT | OUPUT |
yyyykz | 0 |
A cat sat on a mat | 6 |
Abracadabra | 5 |
Eutopia | 5 |