Advertisement
Programmin-in-Python

Words containing Even Number of Vowels in a file

Dec 23rd, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. def displ():
  2.     res = ()
  3.  
  4.     def even_vowels(str1):
  5.         no_vow = 0
  6.         vowels = ('a', 'e', 'i', 'o','u')
  7.  
  8.         for i in str1:
  9.             if i.lower() in vowels:
  10.                 no_vow += 1
  11.  
  12.         return (no_vow%2 == 0)
  13.  
  14.     with open("poem.txt") as file:
  15.         L1 = file.readlines()
  16.  
  17.         for i in L1:
  18.             words = i.split(" ")
  19.             print(words)
  20.  
  21.             for j in words:
  22.                 if even_vowels(j):
  23.                     res += (j,)
  24.  
  25.     print("\nWords containing Even no. of Vowels :")
  26.     for i in res:
  27.         print(rf"'{i}'", end = " ")
  28.     print("\nNumber of Words : ", len(res))
  29.  
  30. displ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement