3.1.2.11 LAB: The continue statement - the Pretty Vowel Eater
LAB
Estimated time
5-10 minutes
Level of difficulty
Easy
Objectives
Familiarize the student with:
- using the
continue
statement 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
for
loop; - the concept of conditional execution (if-elif-else)
- the
continue
statement.
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 methodsand theupper()
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; - assign the uneaten letters to the
wordWithoutVovels
variable 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:
wordWithoutVovels = ""
ReplyDeleteuser=input("enter a word")
for letter in user:
if letter == 'a':
continue
elif letter == 'e':
continue
elif letter == 'i':
continue
elif letter == 'o':
continue
elif letter == 'u':
continue
else:
wordWithoutVovels = wordWithoutVovels + letter
print(wordWithoutVovels.upper())
It should be:
DeleteuserWord = str(input("Ingresa una palabra: "))
userWord = userWord.upper()
x=""
for letter in userWord:
if letter == str("A"):
continue
elif letter == str("E"):
continue
elif letter == str("I"):
continue
elif letter == str("O"):
continue
elif letter == str("U"):
continue
else:
x = letter
print(x)
att LAAJ Mex
DeleteThese Methods don't work
DeletewordWithoutVowels = ""
ReplyDeleteuserWord = input("Enter your word: ")
userWord = userWord.upper()
for letter in userWord:
if letter == "A":
continue
elif letter == "E":
continue
elif letter == "I":
continue
elif letter == "O":
continue
elif letter == "U":
continue
else:
wordWithoutVowels += letter
print(wordWithoutVowels)
wordWithoutVowels = ""
ReplyDeleteuserWord = input("Enter your word: ")
userWord = userWord.upper()
for letter in userWord:
if letter == "A":
continue
elif letter == "E":
continue
elif letter == "I":
continue
elif letter == "O":
continue
elif letter == "U":
continue
else:
wordWithoutVowels += letter
print(wordWithoutVowels)
REPLY
wordWithoutVowels = ""
ReplyDeleteuserWord = input("Enter your word: ")
userWord = userWord.upper()
for letter in userWord:
if letter == "A":
continue
elif letter == "E":
continue
elif letter == "I":
continue
elif letter == "O":
continue
elif letter == "U":
continue
wordWithoutVowels += letter
else:
print(wordWithoutVowels)
IT'S BEING TESTED AND WORKS!
DeleteEven though those answers work, this one is way less to type.
ReplyDelete# Prompt the user to enter a word
# and assign it to the user_word variable.
userWord = input("Enter a word: ")
userWord = userWord.upper()
for letter in userWord:
# Complete the body of the for loop.
if letter in "AEIOU":
continue
print(letter)
I take that back, this is for the lab before the one posted above. My bad. xD
DeleteThis is still easier than all those continues.
DeletewordWithoutVowels = ""
userWord = input("Enter a word: ")
userWord = userWord.upper()
for letter in userWord:
# Complete the body of the for loop.
if letter in "AEIOU":
continue
wordWithoutVowels = wordWithoutVowels + letter
print(wordWithoutVowels)
squalablie-bu Melissa Mitchell https://wakelet.com/wake/4BOFLb1uDSf5SLP3xwzwD
ReplyDeletelaycontoter
word_without_vowels = ""
ReplyDeleteuserWord = input("Enter a word: ")
userWord = userWord.upper()
# Prompt the user to enter a word
# and assign it to the user_word variable.
for letter in userWord:
# Complete the body of the loop.
if letter in "AEIOU":
continue
word_without_vowels = letter
print(word_without_vowels)
# Print the word assigned to word_without_vowels.
This works exactly as required..