I need help understanding how to verify an input. What is the proper syntax? Whenever I try to run this code no matter the input the print functions print. Why is this the case?

A function

def ask():
    ask = input ("type y/n: ")
    ask == "Y" or "y"
  if ask != "Y" or "y":
       print("problem")

it always returns “problem”

Comparisons in Python, like in most programming languages, do not work in the informal way that they do in English or other human languages. The English word “or” in fact means multiple different things.

To use or in a Python program, there needs to be a complete condition that you are checking on each side of it. If you write ask != "Y" or "y", then on one side there is ask != "Y" which is fine, but on the other side there is just "y", which will always satisfy the condition because it is not an empty string.

For more information, please read:

Please also be careful with your indentation when writing (or posting) code. Python is fairly strict about it, because indentation is how it knows the structure of the program, and it does not want to guess if there is any chance of doubt.

To explain this another way that may be more visually intuitive, you appear to intend the code to work something like

  if ask != ("Y" or "y"):

But in fact, the actual meaning is equivalent to

  if (ask != "Y") or ("y"):

To check that a value is equal or not equal to one of a set of n possibilities, you could use a series of n == /!= comparisons chained by ors. However, using the in/not in operator instead of ==/!=` will allow you to do the same thing more concisely and efficiently, and be closer to your original naive syntax and your intuition. I.e.

   if ask not in {"Y", "y"}:

(Note that I used a set as it is most efficient and semantically appropriate here, but any container type will work for the values).