~1 min read • Updated Oct 12, 2025
Program Overview
This Python program reads a single character from the user and determines its type.
It checks whether the character is a digit, an uppercase letter, or a lowercase letter.
The result is displayed using a variable that stores the character type.
Python Code:
def detect_character_type(ch: str) -> str:
if ch.isdigit():
return "Digit"
elif ch.isupper():
return "Uppercase Letter"
elif ch.islower():
return "Lowercase Letter"
else:
return "Other"
# Read character from user
char = input("Enter a single character: ").strip()
if len(char) != 1:
print("Please enter exactly one character.")
else:
result = detect_character_type(char)
print(f"The character '{char}' is a: {result}")
Sample Output (input: A):
The character 'A' is a: Uppercase Letter
Step-by-Step Explanation:
- The user enters a single character
- The program checks its type using built-in string methods:
.isdigit(), .isupper(), and .islower()
- The result is stored in a variable and displayed
- If the input is not a single character, an error message is shown
Written & researched by Dr. Shahin Siami