Header Ads Widget

Python program to check whether a character is uppercase or lowercase alphabet

  

 Python program to check whether a character is uppercase or lowercase alphabet

Given a character , write a program to check whether it is uppercase or lowercase .

Method 1: By using standard function ( isupper() and islower() ) .

Method 2: By Checking range i.e ( if Character is in range A to Z then uppercase ).

Method 3: By using Ascii values . (Ascii of A to Z is 65 to 90 and Ascii value of a to z is 97 to 122 )

Sample input

A 

Sample output

A is Uppercase

Python program to check whether a character is uppercase or lowercase alphabet

The objective of the code is to check whether it is uppercase or lowercase alphabet .

Method 1:

ch=input()
if len(ch)>1:
print("Invalid input")
else:
if ch.isupper():
print(f"{ch} is Uppercase")
elif ch.islower():
print(f"{ch} is Lowercase")
else:
print("Invalid input")


Output:-

A
A is Uppercase

Method 2:

ch=input()
if len(ch)>1:
print("Invalid input")
else:
if ch>='A' and ch<='Z':
print(f"{ch} is Uppercase")
elif ch>='a' and ch<='z':
print(f"{ch} is Lowercase")
else:
print("Invalid input")

Output:-

A
A is Uppercase

Method 3 : (By using Ascii value)

ch=input()
if len(ch)>1:
print("Invalid input")
else:
c=ord(ch)
if c>=65 and c<=90:
print(f"{ch} is Uppercase")
elif c>=97 and c<=122:
print(f"{ch} is Lowercase")
else:
print("Invalid input")

Output:-

A
A is Uppercase

Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-

Post a Comment

0 Comments