Computer Science, asked by santoshprince1634, 1 year ago

Write a Python program to input any character and check whether it is alphabet, digit or special
character

Answers

Answered by Equestriadash
9

The following codes will have to be typed in script mode, saved and then executed.

CODE:

x = input()

if ord(x) >= 65 and ord(x) <= 90:

   print(x, "is an UPPERCase character.")

elif ord(x) >= 97 and ord(x) <= 122:

   print(x, "is a LOWERCase character.")

elif ord(x) >= 48 and ord(x) <= 57:

   print(x, "is a number.")

else:

   print(x, "is a special character.")

We've made use of the IF - ELIF conditional statement, logical operators and an ord() statement.

Once the user inputs a value, the system checks for its ASCII value.

ASCII stands for American Standard Code for Information Interchange. It is a code that holds a value for each character on the keyboard. As Python is case - sensitive, the interpreter will require a medium of language translating. The ASCII holds a value for each character. For instance, the ASCII value of the letter 'A' is 65 and that of the letter 'Z' is 90.

Similarly, the ASCII has values for lowercase letters, numbers and special characters.

The system verifies with the ASCII values [through the ord() statement] and if it holds true, it will print the required statement.

Similar questions