0

I want to check if the information someone has inputted is a letter or not

a=input("Input one letter: ")
#This doesn't actually work
if a==letter:
  print("wow u inputted a letter")
else:
  print("not a letter")

also, I don't want to have to make 26 if statements

2 Answers2

1

There is a constant called ascii_letters in the string library:

from string import ascii_letters # 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'

a = input("Input one letter: ")
if a in list(ascii_letters): # Convert to list so that each element is one character
    print('This is a letter')
else:
    print('This is not a letter')

For lowercase, use string.ascii_lowercase, and for uppercase, use string.ascii_uppercase

The Thonnu
  • 3,578
  • 2
  • 8
  • 30
0

You can also use python's built-in functions str.isalpha and len combined like so:

a.isalpha() and len(a) == 1
game0ver
  • 1,250
  • 9
  • 22