• Write the program to Count the Number of Each Vowel in python technology?

    Answered

    Write the program to Count the Number of Each Vowel in python technology?

    Silver Member Asked on June 5, 2018 in Python.
    Add Comment
  • 1 Answer(s)
    Best answer
    
    # Program to count the number of each vowel in a string
    
    # string of vowels
    
    vowels = 'aeiou'
    
    # change this value for a different result
    
    ip_str = 'Hello, have you tried our turorial section yet?'
    
    # uncomment to 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—————–

    
    >>>
    
    RESTART: D:/python/PythonLogic/Write the program to Count the Number of Each Vowel in python technology.py
    
    {'a': 2, 'e': 5, 'i': 3, 'o': 5, 'u': 3}
    
    

    Silver Member Answered on June 5, 2018.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.