;

Python Program to Check if a Character is Uppercase or not using ASCII Values


Tutorialsrack 22/04/2020 Python

In this Python program, we will learn how to check if a character is uppercase or not using ASCII values. For checking if a character is an uppercase alphabet or not, we will use if...elif...else statement and ord() function to convert a character to an ASCII value and compare it with predefined ASCII value range which starts from 0 to 127. For checking if a character is an uppercase alphabet or not, enter the alphabet from a-z or A-Z.

Here is the code of the program to check if a character is uppercase or not using ASCII values.

Python Program to Check if a Character is Uppercase or not using ASCII Values
# Python Program to Check if a Character is Uppercase or not using ASCII Values

# Take the Input From the User
ch = input("Enter Any Character: ")

if(ord(ch) >= 65 and ord(ch) <= 90):
    print("The Given Character", ch, "is a Uppercase Alphabet")
elif(ord(ch) >= 97 and ord(ch) <= 122):
    print("The Given Character", ch, "is Not a Uppercase Alphabet")    
else:
    print("The Given Character", ch, "is Not an Alphabet Character")
Output

Enter Any Character: Z

The Given Character Z is an Uppercase Alphabet

 

Enter Any Character: z

The Given Character z is Not an Uppercase Alphabet

 

Enter Any Character: 6

The Given Character 6 is Not an Alphabet Character

 

Enter Any Character: %

The Given Character % is Not an Alphabet Character


Related Posts



Comments

Recent Posts
Tags