Q.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 NoVowel should store ['DRY', 'RHYTHM', 'GYM'] And the output should be displayed as GYM RHYTHM DRY EmptyStack
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Part (a): push vowel-free words onto a list stack, pop them → GYM RHYTHM DRY EmptyStack. Part (b): push numbers divisible by 3 or 5, pop them → 30 18 6 10 StackEmpty.
A Python list works as a stack: append() pushes onto the top and pop() removes the top (LIFO).
Part (a)
PushNV(N) walks the list of words and keeps those that contain no vowel (checked case-insensitively). The words are pushed in input order, so the last vowel-free word sits on top and pops first.
NoVowel = []
def PushNV(N):
for word in N:
if not any(ch in "AEIOUaeiou" for ch in word):
NoVowel.append(word)
All = []
print("Enter 5 words:")
for i in range(5):
All.append(input())
PushNV(All)
while len(NoVowel) > 0:
print(NoVowel.pop())
print("EmptyStack")
With ['DRY','LIKE','RHYTHM','WORK','GYM'], LIKE and WORK contain vowels and are skipped, so NoVowel = ['DRY','RHYTHM','GYM']. Popping the top each time prints:
GYM
RHYTHM
DRY
EmptyStack …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.