1.

Write a program to determine whether the entered character is in uppercase or lowercase, or is an invalid character.

Answer»

Language-used:

Python

Program

CHAR = input("Enter a character")

if ord(char) >= 65 or ord(char) <= 90:

   print(char," is upper-CASE")

elif ord(char) >= 97 or ord(char) <= 112:

   print(char," is lower-case")

else:

   print(char," is invalid character")

# 65 - 90(CAPS)

# 97 - 112 (SMALLS)

Output:

Enter a character

Z

90

Explanation

  1. first i turned taken character into its ASCII formate and checked from 65 to 90 because upper-case English alphabets starts at 65
  2. if true i will print it as upper case
  3. else i will check again from 97 to 112 because the lower case English alphabets starts at 97 and ends at 112
  4. if true then i will print it as lower-case
  5. else if the both the condition are false then i will print it as invalid character

------HOPE this help   :)



Discussion

No Comment Found