Friday, December 27, 2024
Google search engine
HomeLanguagesPython Program to Check Given Input is Alphabet, Number or Special Character

Python Program to Check Given Input is Alphabet, Number or Special Character

Python program to check whether the given input is alphabet, number or special character; In this tutorial, you will learn how to check whether the given input is alphabet, number or special character in python.

Python Program to Check Given Input is Alphabet, Number or Special Character

  • Python program to check whether the given input is alphabet, number or special character
  • Python Program to check character is Alphabet, Digit or Special Character using isalpha, isdigit functions.
  • Python Program to check character is Alphabet, Digit or Special Character using ASCII.

1: Python program to check whether the given input is alphabet, number or special character

Use the following steps and write a program to check whether the given input is alphabet number or special character in python:

  • Take input any characters/number/special character from user.
  • Then, Use if statement checks whether the given input character is between a and z or A and Z. If TRUE, it is an alphabet.
  • If condition returns false, it enters into elif statement. Inside the Elif, we are checking whether a character is between 0 and 9. If True, it is a digit.
  • If elif condition returnsfalse, it is a or special character.
# Python Program to check whether the given input is alphabet, number or special character

ch = input("Please Enter Any Character : ")

if((ch >= 'a' and ch <= 'z') or (ch >= 'A' and ch <= 'Z')): 
    print("The Given Character ", ch, "is an Alphabet") 
elif(ch >= '0' and ch <= '9'):
    print("The Given Character ", ch, "is a Digit")
else:
    print("The Given Character ", ch, "is a Special Character")

Output

Test 1

Please Enter Any Character :  ?
The Given Character  ? is a Special Character

Test 2

Please Enter Any Character :  h
The Given Character  h is an Alphabet

2: Python Program to check character is Alphabet, Digit or Special Character using isalpha, isdigit functions

Using string functions isdigit and isalpha to check whether a given character is an alphabet, digit, or any special character in python:

  • Take input any characters/number/special character from user.
  • Then, Use if statement checks whether the given input character is between 1 to 9. If TRUE, it is an digit.
  • If condition returns false, it enters into elif statement. Inside the Elif, we are checking whether a character is between a to z and A to Z. If True, it is a alphabet.
  • If elif condition returnsfalse, it is a or special character.
# Python Program to check whether the given input is Alphabet, Digit or Special Character

ch = input("Please Enter Any Character : ")

if(ch.isdigit()):
    print("The Given Character ", ch, "is a Digit")
elif(ch.isalpha()):
    print("The Given Character ", ch, "is an Alphabet")
else:
    print("The Given Character ", ch, "is a Special Character")

Output

Test 1

Please Enter Any Character :  5
The Given Character  5 is a Digit

Test 2

Please Enter Any Character :  D
The Given Character  D is an Alphabet

Test 3

Please Enter Any Character :  &
The Given Character  & is a Special Character

3: Python Program to check character is Alphabet, Digit or Special Character using ASCII.

Use the following steps and write a program to check whether the given input is alphabet, digit or special character using ascii in python:

  • Take input characters from user.
  • Then test condition using if elfi else statement in python with ASCII Value.
  • Print the result.
# Python Program to check whether the given input is Alphabet, Digit or Special Character using ascii

ch = input("Please Enter Any Character : ")

if((ch >= 'a' and ch <= 'z') or (ch >= 'A' and ch <= 'Z')): 
    print("The Given Character ", ch, "is an Alphabet") 
elif(ch >= '0' and ch <= '9'):
    print("The Given Character ", ch, "is a Digit")
else:
    print("The Given Character ", ch, "is a Special Character")

Output

Please Enter Any Character :  A
The Given Character  A is an Alphabet

Recommended Python Programs

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments