Start Your Journey with Linux Command Line
![]() |
| the Ugly Vowel Eater |
If you're taking PCAP - Programming Essentials In Python , you may have encountered this question in 3.2.1.10 LAB: The continue statement - the Ugly Vowel Eater.
Familiarize the student with:
using the continue statement in loops;
reflecting real-life situations in computer code.
The continue statement is used to skip the current block and move ahead to the next iteration, without executing the statements inside the loop.
It can be used with both the while and for loops.
Your task here is very special: you must design a vowel eater! Write a program that uses:
a for loop;
the concept of conditional execution (if-elif-else)
the continue statement.
Your program must:
ask the user to enter a word;
use user_word = user_word.upper() to convert the word entered by the user to upper case; we'll talk about the so-called string methods and the upper() method very soon - don't worry;
use conditional execution and the continue statement to "eat" the following vowels A, E, I, O, U from the inputted word;
print the uneaten letters to the screen, each one of them on a separate line.
Test your program with the data we've provided for you.
Sample input: Gregory
Expected output:
G
R
G
R
Y
Sample input: abstemious
Expected output:
B
S
T
M
S
Sample input: IOUEA
Expected output:
I
O
U
E
A
In below video, we will see how for loop works. It checks each condition with the statements inside the block. If True then the condition is exempted/passed
If letter == "A":
continue
This means, if the letter equals "A", the letter is passed and not shown
=================================================================================
The Ugly Vowel Eater is a lab that teaches the continue statement, which stops the current iteration of a loop and jumps straight to the next one without executing any further statements inside the loop body. It works with both while and for loops. In this exercise the program reads a word, converts it to upper case with user_word = user_word.upper(), and then walks through the word one letter at a time with a for loop.
Inside the loop the code uses conditional execution to recognize the five vowels A, E, I, O, and U. For each letter it tests whether the character matches one of these vowels using a chain of if, elif, and else branches. When a vowel is matched, the matching branch executes continue, which abandons the rest of the loop body for that letter. Because the only remaining statement in the loop is print(letter), a vowel is never printed; the else branch runs only for consonants and displays them, one per line.
Considering the word Gregory, the loop skips the vowels G-r-e-g-o-r-y, leaving the consonants G, R, G, R, and Y printed on separate lines, exactly matching the expected output. For the unusual word abstemious, which contains the vowels a, e, i, o, and u, the program prints only the consonants B, S, T, M, and S. Even a word made entirely of vowels, like IOUEA, still produces output, because every vowel triggers continue and each vowel appears on its own line while the word also contains no consonants to suppress. This demonstrates that continue skips the current iteration but does not end the loop.
continue statement jumps to the next iteration, skipping any code that follows it in the loop body.while and for loops.user_word.upper() makes the vowel comparison case-insensitive.continue to prevent it from being printed.else branch runs only for consonants, printing each one on a separate line.continue does not terminate the loop.Continue skips only the current iteration and lets the loop move to the next one, while break exits the loop entirely.
So that both uppercase and lowercase vowels are recognized by a single set of comparisons, since upper() normalizes every letter.
Yes. Continue behaves the same way in while loops, skipping the rest of the body and evaluating the loop condition again.
In the provided solution the else branch prints whatever is not a vowel, and every vowel triggers continue instead, so only the else output appears.
Comments
Post a Comment
Your opinion matters, your voice makes us proud and happy. Your words are our motivation.