Stacks In Python 8

Write a program to display vowels present in the given word using stacks.

Source Code

vowels=['a','e','i','o','u','A','E','I','O','U']
word=input("Enter the word ")
stack=[]
for letter in word:
    print(letter)
    if letter in vowels:
        stack.append(letter)

print("stack ",stack)
print("total different unique vowels are ",len(stack))

Output:

Enter the word computer
c
o
m
p
u
t
e
r
stack  ['o', 'u', 'e']
total different unique vowels are  3

Write a program to display unique vowels present in the given word using stacks.

Source Code

vowels=['a','e','i','o','u','A','E','I','O','U']
word=input("Enter the word ")
stack=[]
for letter in word:
    print(letter)
    if letter in vowels:
        
        if letter not in stack:
            stack.append(letter)

print("stack ",stack)
print("total different unique vowels are ",len(stack))

Output:

Enter the word hello
h
e
l
l
o
stack  ['e', 'o']
total different unique vowels are  2
Enter the word hellooooo
h
e
l
l
o
o
o
o
o
stack  ['e', 'o']
total different unique vowels are  2

Visitor Counter

0056683