Skip to content
Question

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

(OR)
Write the definition of a user defined function Push3_5(N) which accepts a list of integers in a parameter N and pushes all those integers which are divisible by 3 or divisible by 5 from the list N into a list named Only3_5. Write a program in Python to input 5 integers into a list named NUM. The program should then use the function Push3_5() to create the stack of the list Only3_5. Thereafter pop each integer from the list Only3_5 and display the popped value. When the list is empty, display the message "StackEmpty". For example: If the integers input into the list NUM are: [10, 6, 14, 18, 30] Then the stack Only3_5 should store [10, 6, 18, 30] And the output should be displayed as 30 18 6 10 StackEmpty
CBSECBSE Class XII Board 2022Subjective· 3mImportance★★★★★
🔒 Locked · start free trial →

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.