Skip to content

Instantly share code, notes, and snippets.

@pavi2410
Last active November 28, 2020 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavi2410/6efddc55ea2e6528d00de158d8df7fa6 to your computer and use it in GitHub Desktop.
Save pavi2410/6efddc55ea2e6528d00de158d8df7fa6 to your computer and use it in GitHub Desktop.
file = open("lorem.txt", "r")
text = file.read()
v = 0
c = 0
u = 0
l = 0
for char in text:
if char.lower() in "aeiou": # this will match char against { a e i o u } and { A E I O U } because char is converted to lowercase
v += 1
else: # else this is a consonant
c += 1
if char.isupper(): # test whether the char is upper
u += 1
else: # or lower
l += 1
file.close()
print("Vowels =", v)
print("Consonants =", c)
print("Lowercase letters =", l)
print("Uppercase letters =", u)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment