Find us on Facebook

Thursday, December 13, 2018

Number of each vowel in a string



Aim: Implement a Program to count the number of each vowel in a string
Algorithm:
1.Start
2.Enter the string s.
3.Take each character in the string and compare with ‘a,e,i,o,u’.
4.If found increment corresponding counter by one.
5.Print the counter values.
6.Stop
Program:
# string of vowels
vowels = 'aeiou'
# take input from the user
ip_str = input("Enter a string: ")
# make it suitable for caseless comparisions
ip_str = ip_str.casefold()
# make a dictionary with each vowel a key and value 0
count = {}.fromkeys(vowels,0)
# count the vowels
for char in ip_str:
   if char in count:
       count[char] += 1
print(count)
Output:
Enter a string: Hello, have you tried our turorial section yet?
{'e': 5, 'u': 3, 'o': 5, 'a': 2, 'i': 3}4)


0 Comments:

Popular Posts

Text Widget

Search This Blog

Powered by Blogger.

Blogger Pages

Like Canvas?

Sponsor

Footer Widgetized Areas

About Canvas

About Canvas

Subscribe Us

About

Text Widget

Tags

Total Pageviews

print pdf

cal

Most Popular

    TUPLES
 LIST and SLICING
      ASCII VALUE
Copyright © KTU Btech Cse Python Lab Manuals | Powered by Blogger
Design by Saeed Salam | Blogger Theme by NewBloggerThemes.com | Distributed By Gooyaabi Templates