Search code examples
pythonpython-3.xfunctionbooleanvar

Confused with Def Python


def yesno(endwhat):
    end = False
    while not end:
        ok = input("<Y/N>")
        if ok.upper == 'Y' or ok.upper == 'N':
            if ok.upper == 'Y':
                end = True
                endwhat = True
        else:
            print("Enter only <Y/N>")
    return(ok)

This Doesn't Work, It Just Repeats even when I put Y or N. I think the problem is when I enter a var in 'endwhat' it doesn't change it to True. Any Help is Truly Appreciated. Thanks...


Solution

  • You forgot to put () to string function.

    def yesno(endwhat):
      end = False
      while not end:
        ok = input("<Y/N>")
        if ok.upper() == 'Y' or ok.upper() == 'N':
            if ok.upper() == 'Y':
                end = True
                endwhat = True
        else:
            print("Enter only <Y/N>")
      return(ok)