I'm new to Python and want to develop good habits at the beginning. This class takes a string, and then counts the number of vowels and consonants in the word(s). Any advice on how to improve?
class CntVowels:
def __init__(self,string):
self.string = string
self.vowels = [ "a", "e", "i", "o", "u"]
def vowel_count(self):
strings = self.string.lower()
vowels = self.vowels
counter = 0
for letter in strings:
for vowel in vowels:
if letter == vowel:
counter += 1
print("There are {} vowels in this string.".format(counter))
def constant_count(self):
strings = self.string.lower()
vowels = self.vowels
length = len(strings)
counter = 0
for letter in self.string:
for vowel in vowels:
if letter == vowel:
counter += 1
results = length - counter
print("There are {} constants in this string.".format(results))
a = input("enter a string")
CntVowels(a).vowel_count()
CntVowels(a).constant_count()