Logic Building
# Take character
ch = input("Enter a character: ")
# Check type
if ch.isalpha():
print("Letter")
elif ch.isdigit():
print("Digit")
else:
print("Neither")Output
Enter a character: a Letter Enter a character: 5 Digit Enter a character: @ Neither
Use string methods to check character type.
Key Concepts:
- isalpha(): checks if letter
- isdigit(): checks if digit
- Otherwise: special character