Instagram
youtube
Facebook
Twitter

Convert Lowercase Vowels to Uppercase in a String

A Python program to convert only lowercase vowels in a string to uppercase while keeping other characters unchanged.

Explanation of the Code:

  • def check_character(string): → Defines a function to process the input string.

  • vowels = "aeiou" → Stores lowercase vowels for comparison.

  • result = "" → Initializes an empty string to store the modified result.

  • for char in string: → Iterates through each character in the input string.

  • if char in vowels: → Checks if the character is a lowercase vowel.

  • result += char.upper() → Converts the vowel to uppercase and adds it to result.

  • else: → If the character is not a vowel, it remains unchanged.

  • result += char → Adds the unchanged character to result.

  • return result → Returns the modified string.

  • char = input("Enter a character: ") → Takes user input.

  • converted_string = check_character(char) → Calls the function and stores the modified string.

  • print("Modified string:", converted_string) → Prints the modified string with uppercase vowels.

Example Output:

Input: hello world
Output: hEllO wOrld

 

Program:

def check_character(string):
    vowels = "aeiou"
    result = ""
    for char in string:
        if char in vowels:
            result += char.upper()
        else:
            result += char
    return result

char = input("Enter a character: ")
converted_string = check_character(char)
print("Modified string:", converted_string)