Estimated time
5-10 minutes
Level of difficulty
Easy
Objectives
Familiarize the student with:
- using the
continuestatement in loops; - modifying and upgrading the existing code;
- reflecting real-life situations in computer code.
Scenario
Your task here is even more special than before: you must redesign the (ugly) vowel eater from the previous lab (3.1.2.10) and create a better, upgraded (pretty) vowel eater! Write a program that uses:
- a
forloop; - the concept of conditional execution (if-elif-else)
- the
continuestatement.
Your program must:
- ask the user to enter a word;
- use
userWord = userWord.upper()to convert the word entered by the user to upper case; we'll talk about the so-called string methods and theupper()method very soon - don't worry; - use conditional execution and the
continuestatement to "eat" the following vowels A, E, I, O, U from the inputted word; - assign the uneaten letters to the
wordWithoutVovelsvariable and print the variable to the screen.
Look at the code in the editor. We've created
wordWithoutVovels and assigned an empty string to it. Use concatenation operation to ask Python to combine selected letters into a longer string during subsequent loop turns, and assign it to the wordWithoutVovels variable.
Test your program with the data we've provided for you.
Test data
Sample input:
Gregory
Expected output:
GRGRY
Sample input:
abstemious
Expected output:
BSTMS
Sample input:
IOUEA
Expected output:
it took me a long time to figure this out.
ReplyDeletewordWithoutVowels = ""
vowels = ("a", "e", "i", "o", "u")
userWord = input("Enter a word: ")
for letter in userWord:
if letter not in vowels:
wordWithoutVowels+= letter
print(wordWithoutVowels.upper())