Friday, July 5, 2019

Counting the number of vowels in a statement

Script

#!/usr/local/bin/python3.7

vowelcount = 0

print()
statement = input('Enter your text (# to exit): ')

for x in statement:
    if x == 'A' or x == 'a' or x == 'E' or x == 'e' or x == 'I' or x == 'i' or x == 'O' \
    or x == 'o' or x == 'U' or x == 'u':
        print(x, ',', sep='', end='')
        vowelcount = vowelcount + 1
    elif x == '#':
        break
print ("\n\nThere are", vowelcount, " vowels in this statement.\n")


Execution


Enter your text (# to exit): Sachin Tendulkar played 200 Tests for India, making his debut in 1989 and playing his last Test in 2013.
a,i,e,u,a,a,e,e,o,I,i,a,a,i,i,e,u,i,a,a,i,i,a,e,i,

There are 25  vowels in this statement.





No comments:

Post a Comment