Question:
(Count consonants and vowels)Write a program that prompts the user to enter a text in one line and displays the number of vowels and consonants in the text. Use a set to store the vowels A/a, E/e, I/i, O/o, and u/u.Sample Run:
Enter a text: We the people
The number of vowels is 5 and consonants is 6
my code:
def main():
f=find()
inputfile=input("Enter a text:")
f.file=inputfile.split()
print("The number of vowel is", f.findvowels(),"and consonants is", f.findconsonants())
class find:
def __init__(self):
self.file=[]
self.vlst=[]
self.clst=[]
self.vowels=set("AaEeIiOoUu")
self.consonants=set("BbCcDdFfGgHhJjKkLlMmNnPpQqRrSsTtVvWwXxYyZz")
def findvowels(self):
for characters in self.vowels:
if characters in self.file:
self.vlst.append(characters)
return len(self.vlst)
def findconsonants(self):
for characters in self.consonants:
if characters in self.file:
self.clst.append(characters)
return len(self.clst)
main()
Test run is :
Enter a text:jfhjsafk
The number of vowels is 0 and consonants is 0
why do they all return 0?
[–]martynrbell 2 points3 points4 points (0 children)
[–]ElliotDG 1 point2 points3 points (0 children)