user_input = input("Enter a single character from the alphabet: ")

if len(user_input) != 1 or not user_input.isalpha():
    print("Error: Please enter a single letter from the alphabet")
else:
    letter = user_input.lower()
    if letter in ['a', 'e', 'i', 'o', 'u']:
        print("Vowel")
    else:
        print("Consonant")

Explanation:

  1. Prompt the user for input using the input() function and store it in a variable called user_input.
  2. Check if the length of the user input is not equal to 1 using the len() function and if the input is not alphabetic using the isalpha() function. If either of these conditions is true, print an error message.
  3. Convert the user input to lowercase using the lower() method and store it in a variable called letter.
  4. Check if the letter is one of the vowels ('a', 'e', 'i', 'o', 'u'). If it is, print "Vowel". Otherwise, print "Consonant".
Write a program that prompts the user to provide a single character from the alphabet Print Vowel or Consonant depending on the user input If the user input is not a letter between a and z or A and Z

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

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