0

Pretty much the title, I am making a hangman game in python and this def is supposed to make sure the input is actually a letter but it's not working, what's wrong?

def guess():    
    while True:
        var = (input())
        if var.isalpha == False or len(var) != 1:
            print ("Not a letter")
        else:
            print ("Is a letter")
guess()
martineau
  • 112,593
  • 23
  • 157
  • 280
samstg09
  • 11
  • 1
  • @roganjosh sorry didn't think it mattered that much just edited them out – samstg09 Jan 10 '20 at 00:53
  • 3
    `isalpha` is a method. You should _call_ it, i.e. `var.isalpha()`. Also `== False` is not recommended. You can use `not var.isalpha()` instead. – Selcuk Jan 10 '20 at 00:54
  • 1
    Looking at `var.isalpha` in the REPL is a good way to see the problem (if it tells you it's a function and not a boolean, that's a big clue). – Charles Duffy Jan 10 '20 at 00:59
  • (aside: the two prior close votes were close-as-typo; I'd argue that the close-as-duplicate approach is a little more useful, since it provides useful guidance for someone who's doing this as a thinko -- f/e, coming from Ruby and accustomed to its implicit-invocation convention -- rather than a typo). – Charles Duffy Jan 10 '20 at 01:01
  • Side-note: For logically boolean stuff, don't compare to `True` or `False`. Just use the result or `not` of the result. e.g. in this case, `if not var.isalpha() or len(var) != 1:`. It's faster and [more Pythonic](https://www.python.org/dev/peps/pep-0008/#programming-recommendations) than explicit comparisons to `True`/`False`. – ShadowRanger Jan 10 '20 at 01:02

1 Answers1

1

Use var.isalpha() since it is a function.

Randy Maldonado
  • 333
  • 1
  • 6