Computer Science, asked by pooniaparmod1151, 11 months ago

Write a program to find whether the given character is a digit or a letter

Answers

Answered by codiepienagoya
1

Find input character is a digit or a letter

Output:

i) please enter character: s

  s is an Alphabet.

ii) please enter character: 3

   3 is a Digit.

Explanation:

program to find input character is digit or a letter as follows:

Program:

x1= input("please enter character: ") #defining variable X1 that input value from user-ends

if(( x1>= 'a' and x1 <= 'z') or (x1 >= 'A' and x1 <= 'Z')): #check condition for Alphabet  

   print(x1,"is an Alphabet.") #print value and message

elif(x1 >= '0' and x1 <= '9'): #check condition for Digit

   print(x1,"is a Digit.") #print value and message

else:

   print(x1,"is not an Alphabet and not a Digit.") #print value and message

Description of the above program as follows:

  • In the above python code, a variable x1 is declared, which uses an input function that provides the facility to take input from the user.
  • In the next line, the conditional statement is used in the if block it checks the input values is in range of A to Z or a to z. if this condition is true it will print the value and "is an Alphabet".
  • Then elif block is defined, which is used when the if block condition is false, in this block it will check the input value is in range 0 to 9, if this condition is true it will print the value and "is a Digit". If both conditions are not true, so it will execute the else part.

Learn more:

  • Input a value: https://brainly.in/question/9034835
Similar questions