Please Help

Write a program that asks for a phrase and then calculates and displays the number of vowels in the phrase, twice. The first time, your program should calculate the number of vowels in the phrase using a for loop. The second time, your program should use a while loop.

1) Get input phrase
2) Calculate number of vowels in phrase with a for loop
3) Calculate number of vowels in phrase with a while loop
4) Output

If needed, you can put an output step after step 2.

Now tackle each one at a time.

- Get string input and put it into a string variable
- Step through the string and compare each letter with each type of vowel using the index operator (ex: mystring[3]) and keep count of the number of each vowel you encounter.
- Print out the data in a readable format

>>>
Please enter a phrase: Programming is fun.
There are 5 vowels in the phrase 'Programming is fun.'.

Here, "for letter in phrase" is the beginning of the for loop. It goes through the phrase letter by letter and executes whatever is in the for loop (indented below that first line) with "letter" being the variable representing the current letter. Does that make sense?

Note: This code only counts lowercase vowels. You'll need to make a change to it if you want to catch all vowels.

Remember how I said that "if letter in VOWELS:" checks if that certain character letter is in the string VOWELS? If you want to check if it's uppercase as well, just add the uppercase vowels to that VOWELS string.

Perfect. That works. You can simplify it by putting those two together:

if letter in VOWELS or letter in VOWELS.upper():
vowel_total += 1

To do it the while loop way, you can have an index count variable that starts at zero and have the while loop go "while the index count is less than the string length". Then inside the while loop you can do that same check above and then increment the index variable.

I got it all together but am hitting an issue. Here is my coding, any idea what is wrong?

while vowel_total < length:
if letter in VOWELS or letter in VOWELS.upper():
vowel_total += 1
print "There is a total of",vowel_total,"vowels in the phrase that you entered, according"
print "to the While Loop."

Note: Please use CODE tags, which can be found in the message editing toolbar. It makes code much easier to read.

The first line of your while statement doesn't really make sense. Overall the loop says "Check to see if letter is in VOWELS while vowel_total is less than the length." You want to use the while loop to go through the letters of the word.

Try adapting this code, which goes through each letter of a string, to your project.

The second problem is that your "if phrase[index] in..." is not in the while loop. It should where the print statement is and you can get rid of the print statement. That was just an example I was showing you.

Finally, you need to copy that print statement that says how many vowels are in the phrase from the first section to the second one.

I don't think you're quite getting the logic of the loop. You start with the index as 0. That way phrase[index] represents the first letter of the phrase, which is a string. phrase[len(phrase) - 1] represents the last letter of the phrase. Using the following logic, you can go through the string Hello one letter at a time and do something with that letter:

In your case, you want to do the comparison in the loop, not print something. The print statement goes after the loop.

Also, you need to reset the vowel_count for the second section because you want to start from 0 again.

With the fixes:

phrase = raw_input("Please enter a phrase: ")
length = len(phrase)
VOWELS = "aeiou"
vowel_total = 0
for letter in phrase:
if letter in VOWELS:
vowel_total += 1
for letter in phrase:
if letter in VOWELS.upper():
vowel_total += 1
print "There is a total of",vowel_total,"vowels in the phrase that you entered."
raw_input("\nPress the enter key to continue to see what the While Loop comes up with.")
phrase = raw_input("Enter your phrase: ")
phrase_length = len(phrase)
index = 0
vowel_count = 0
while index < phrase_length:
if phrase[index] in VOWELS or phrase[index] in VOWELS.upper():
vowel_total += 1
index += 1
print "There is a total of",vowel_total,"vowels in the phrase that you entered."

Wow I get it now. I actually did have to reset the vowel_total on the second part otherwise it continued to add onto the results from the for loop. Thank you so much! I have been workin on this thing for literally three or four hours! I extremely appreciate it!

Hi. so this is actually a continuation from another question of mine[Here](https://www.daniweb.com/programming/software-development/threads/506795/dynamically-add-values-into-datagridview-cell-from-listbox-vb2010) but i was advised to start a new thread as the original question …

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...