cs/practical-file/questions/question_11_output.txt
2025-06-24 02:37:47 +05:30

30 lines
958 B
Plaintext

Question 11:
Write a Python program to check whether a given character is a vowel or consonant.
Answer:
def main(char: str) -> None:
vowels = 'aeiou'
if char.lower() in vowels:
print(f"{char} is a vowel.")
elif char.isalpha():
print(f"{char} is a consonant.")
else:
raise ValueError("Invalid input. Please enter an alphabetic character.")
if __name__ == '__main__':
main('a')
main('b')
main('A')
main('1') # also works with a int
Output:
Traceback (most recent call last):
File "\\homeassistant.local\share\data\school\Grade 11 CS\Practical File\question_11.py", line 17, in <module>
main('1') # also works with a int
^^^^^^^^^
File "\\homeassistant.local\share\data\school\Grade 11 CS\Practical File\question_11.py", line 10, in main
raise ValueError("Invalid input. Please enter an alphabetic character.")
ValueError: Invalid input. Please enter an alphabetic character.