এই প্রোগ্রামে, একটি ব্যবহারকারীর ইনপুট স্ট্রিং দেওয়া. আমাদের এই স্ট্রিংটিতে স্বরবর্ণের সংখ্যা গণনা করতে হবে। এখানে আমরা পাইথনে সেট ব্যবহার করি। সেট হল একটি ক্রমবিহীন সংগ্রহের ডেটা টাইপ যা পুনরাবৃত্তিযোগ্য, পরিবর্তনযোগ্য এবং কোনো সদৃশ উপাদান নেই।
উদাহরণ
Input str1=pythonprogram Output 3
অ্যালগরিদম
Step 1: first we use one counter variable which is used to count the vowels in the string. Step 2: creating a set of vowels. Step 3: then traverse the every alphabet in the given string. Step 4: if alphabet is present in the vowel set then counter incremented by 1. Step 5: After the completion of traversing print counter variable.
উদাহরণ কোড
# Program to count vowel in
# a string using set
def countvowel(str1):
c = 0
# Creating a set of vowels
s="aeiouAEIOU"
v = set(s)
# Loop to traverse the alphabet
# in the given string
for alpha in str1:
# If alphabet is present
# in set vowel
if alpha in v:
c = c + 1
print("No. of vowels ::>", c)
# Driver code
str1 = input("Enter the string ::>")
countvowel(str1) আউটপুট
Enter the string ::>pythonprogram No. of vowels ::> 3