Difference between revisions of "Count the Vowel"

From CompSciWiki
Jump to: navigation, search
m (Sentences start with a capital and end with a period.)
m (Change we've to we're. Added in more missing periods to sentences.)
Line 16: Line 16:
 
}}<br />
 
}}<br />
  
Second, we need get the input using raw_input(prompt)
+
Second, we need get the input using raw_input(prompt).
 
{{CodeBlock
 
{{CodeBlock
 
|Code=
 
|Code=
Line 25: Line 25:
 
}}<br />
 
}}<br />
  
Third, we need to check the vowel
+
Third, we need to check the vowel.
 
{{CodeBlock
 
{{CodeBlock
 
|Code=
 
|Code=
Line 34: Line 34:
 
}}<br />
 
}}<br />
  
Then we need to use while loop to print the output
+
Then we need to use while loop to print the output.
  
 
{{CodeBlock
 
{{CodeBlock
Line 46: Line 46:
 
}}<br />
 
}}<br />
  
Now we've done. You should write a complete program.
+
Now we're done. You should write a complete program.
  
 
|SolutionCode=
 
|SolutionCode=

Revision as of 19:08, 4 April 2012

Back to the Program-A-Day homepage

Problem

Count the number of vowels in a string given by the user.

 

String Methods

SideSection goes here.

Solution

First, we need 3 variables:

  • input - holding the user's input
  • done - control the while loop
  • vowelCount - count the number of vowel
     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 != '': 

    Third, 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're done. You should write a complete program.

  • Code

    Solution Code

    Back to the Program-A-Day homepage