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:
  • 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 the upper() method very soon - don't worry;
  • use conditional execution and the continue statement to "eat" the following vowels AEIOU 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 = ""
# Prompt the user to enter a word
# and assign it to the userWord variable
for letter in userWord:
# Complete the body of the loop.
# Print the word assigned to wordWithoutVowels.
  • Console 

Comments

  1. wordWithoutVovels = ""
    user=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())

    ReplyDelete
    Replies
    1. It should be:

      userWord = 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)

      Delete
  2. wordWithoutVowels = ""

    userWord = 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)

    ReplyDelete
  3. wordWithoutVowels = ""

    userWord = 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

    ReplyDelete
  4. wordWithoutVowels = ""

    userWord = 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)

    ReplyDelete
  5. Even though those answers work, this one is way less to type.

    # 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)

    ReplyDelete
    Replies
    1. I take that back, this is for the lab before the one posted above. My bad. xD

      Delete
    2. This is still easier than all those continues.

      wordWithoutVowels = ""
      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)

      Delete
  6. word_without_vowels = ""
    userWord = 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..

    ReplyDelete

Post a Comment

Popular Posts