English

Write the definition of a user defined function PushNV(N) which accepts a list of strings in the parameter N and pushes all strings which have no vowels present in it, into a list named NoVowel. - Computer Science (Python)

Advertisements
Advertisements

Question

  • Write the definition of a user defined function PushNV(N) which accepts a list of strings in the parameter N and pushes all strings which have no vowels present in it, into a list named NoVowel.
  • Write a program in Python to input 5 words and push them one by one into a list named All.
    The program should then use the function PushNV() to create a stack of words in the list NoVowel so that it stores only those words which do not have any vowel present in it, from the list All. Thereafter, pop each word from the list NoVowel and display the popped word. When the stack is empty display the message "EmptyStack".

For example:

If the Words accepted and pushed into the list All are

['DRY', 'LIKE', 'RHYTHM', 'WORK', 'GYM']

Then the stack No Vowel should store

['DRY', 'RHYTHM', 'GYM']

And the output should be displayed as

GYM RHYTHM DRY EmptyStack

Code Writing

Solution

No Vowel = []
def PushNV(N):
      for i in range(len(N)) :
if 'A' in N[i] or 'E' in N[i] or 'I' in N[i] or 'O' in N[i] or 'U' in N[i]:
     pass
else:
     NoVowel.append(N[i])
All=[]
for i in range(5):
     w=input("Enter Words:")
     All.append(w)
PushNV(All)
while True:
     if len(NoVowel) == 0:
         print("EmptyStack")
         break
     else:
         print(NoVowel.pop(), " ", end='')

Output:

shaalaa.com
  Is there an error in this question or solution?
2021-2022 (April) Set 4
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×