Python Program for Vowel and Consonant Case Conversion

Python Program for Vowel and Consonant Case Conversion

 

Instructions

This Python practice consists of creating a program for vowel and consonant case conversion.  Your task is to write a command line program that prompts the user to enter a sentence or phrase. The program should then convert all vowels contained in the input sentence to uppercase and all consonants to lowercase. The modified sentence or phrase should be displayed as the output.

Steps:

  1. Prompt the user to enter a sentence or phrase.
  2. Store the user input in a variable.
  3. Create an empty string variable to store the modified sentence.
  4. Iterate through each character in the input sentence.
  5. Check if the character is a vowel (a, e, i, o, u, or their uppercase counterparts).
  6. If the character is a vowel, convert it to uppercase and add it to the modified sentence.
  7. If the character is a consonant, convert it to lowercase and add it to the modified sentence.
  8. Display the modified sentence as the output.

Expected Output

Sentence input by the user: “Hello, World!”

Output: “hEllO, wOrld!”

Python Exercise Source Code


# Prompt the user to enter a sentence or phrase
sentence = input("Enter a sentence or phrase: ")

# Create an empty string variable to store the modified sentence
modified_sentence = ""

# Iterate through each character in the input sentence
for char in sentence:
# Check if the character is a vowel
   if char.lower() in ['a', 'e', 'i', 'o', 'u']:
# Convert the vowel to uppercase and add it to the modified sentence
      modified_sentence += char.upper()
   else:
# Convert the consonant to lowercase and add it to the modified sentence
      modified_sentence += char.lower()

# Display the modified sentence
print("Modified sentence:", modified_sentence)

Benefits

The aim of this type of Python exercises that focus on lists, “for” loops, and basic built-in functions, is that students can apply the concepts they have learned in courses to practical applications. This not only helps solidify their understanding of these key programming elements but also allows them to become more comfortable with coding syntax and logic.

The goal of this Python assignment in particular is to give students the opportunity to work with lists, which are fundamental data structures in Python and “for” loops. These are crucial skills in programming since they allow to automate repetitive tasks, save time and effort and write more efficient code.

We will be happy to hear your thoughts

Leave a reply

Python and Excel Projects for practice
Register New Account
Shopping cart