Advertisements
Advertisements
प्रश्न
- Write the definition of a user defined function
PushNV(N)which accepts a list of strings in the parameterNandpushesall strings which have no vowels present in it, into a list namedNoVowel. - Write a program in Python to input 5 words and
pushthem one by one into a list named All.
The program should then use the functionPushNV()to create a stack of words in the listNoVowelso that it stores only those words which do not have any vowel present in it, from the listAll. Thereafter,popeach word from the listNoVoweland 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
कोड लेखन
Advertisements
उत्तर
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
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
