Skip to Main Content
Blog

Count English Letters in Python

Count English Letters in Python

def main():
	"""
	Counts the number of vowels in a string.
	"""

	txt = input("Enter string: ")

	vow = set("AEIOUaeiou")
	ctr = 0
	for c in txt:
		if c in vow:
			ctr += 1

	print(ctr)


if __name__ == "__main__":
	main()
def main():
	text = input("Enter string: ").lower()

	vowels = {"a", "e", "i", "o", "u"}
	count = 0

	for c in text:
		if "a" <= c <= "z" and c not in vowels:
			count += 1

	print("Consonants:", count)


if __name__ == "__main__":
	main()