Python Forum

Full Version: Conditional
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to design a condition yes/no statement questions and I cannot figure out what I am doing wrong :(
name = input("What is your name? ")
print ("Hello " + name + ", nice to meet you. ")
answer = input("Do you want to identify a mineral? (y/n)")
if answer == "y" or "Y":
  print ("Great," + name + " ,let's get started")
elif answer == "n" or "N":
  print ("Ok," + name + " ,come back when you have a mineral to identify")
This is a precedence issue. Your if statement is parsed as:

if (answer == "y") or ("Y"):
Answer == "y" may not be true, but "Y" is always true. Your test should presumably instead be either

if answer == "y" or answer == "Y":
or...

if answer in ["y", "Y"]:
(Jan-13-2021, 06:53 PM)bowlofred Wrote: [ -> ]This is a precedence issue. Your if statement is parsed as:

if (answer == "y") or ("Y"):
Answer == "y" may not be true, but "Y" is always true. Your test should presumably instead be either

if answer == "y" or answer == "Y":
THANK YOU!!!!
or...

if answer in ["y", "Y"]:
Thank you!!!