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…

Answer

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)

Leave a Reply

Your email address will not be published. Required fields are marked *