Count the Vowel

From CompSciWiki
Revision as of 19:20, 3 April 2012 by YulinT (Talk | contribs)

Jump to: navigation, search

Back to the Program-A-Day homepage

Problem

count the number of vowels in a string given by the user

 

String Methods and Debugging

SideSection goes here.

Solution

First, we need 3 variables:

  • input -
  • done -
  • vowelCount -
     done = False
    vowelCount = 0 


    Second, we need get the input using raw_input(prompt)

     #get the input from user
    input = raw_input("Enter a sentence")
    
    if input != ' ': 

    Then we need to check the vowel

     input = input.lower()
    for char in inputs:
      #//check if it's a vowel
      if char == 'a' : 

    Then we need to use while loop to print the output

     while(!done):
      (...)
      #output result
      print '\nVowel count: %d\nVowel percentage: %d%%' % \
      (vowelCount, vowelCount * 100 / leng(input)) 

    Now we've done. You should write a complete program.

  • Code

    Solution Code

    Back to the Program-A-Day homepage