Here's a Python function to determine if a character is a vowel:

def check_vowel(char):
    vowels = ['a', 'e', 'i', 'o', 'u']
    if char.lower() in vowels:
        print(f"The character '{char}' is a vowel.")
    else:
        print(f"The character '{char}' is not a vowel.")

# Example usage:
user_input = input("Enter a character: ")
check_vowel(user_input)

Explanation:

  • check_vowel(char): This function takes a single character (char) as input.
  • vowels = ['a', 'e', 'i', 'o', 'u']: A list containing all lowercase vowels is created.
  • char.lower() in vowels: The function converts the input character to lowercase and checks if it's present in the vowels list.
  • print(f"The character '{char}' is a vowel."): If the character is found, it prints a message indicating it's a vowel.
  • print(f"The character '{char}' is not a vowel."): If the character is not found, it prints a message indicating it's not a vowel.
  • User Input: The code prompts the user to enter a character, stores it in the user_input variable, and calls the check_vowel function with this input.
Python Function to Check if a Character is a Vowel

原文地址: https://www.cveoy.top/t/topic/paBR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录