In: Computer Science
Python only please - Write a Python code to read a character (only one character) from the user and check if it is a letter, digit, or a special character. Please see the sample runs below:
Sample Run 1
Enter a character: g
It is a letter
Sample Run 2
Enter a character: 7
It is a digit
Sample Run 3
Enter a character: @
It is a special character
Code with explanation in comments:
#read user input in character
character=input("Enter a character: ")
#check if user entered only one character
if len(character)==1:
#check if character is letter,digit or special character
if character.isalpha():
print("It is a letter")
elif character.isdigit():
print("It is digit")
else:
print("It is a special character")
else:
print("Please enter only one character")
-------------------------------------------------------------------------------------------------
screenshot of Output with code:


