Python Forum
Conditional - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Conditional (/thread-31990.html)



Conditional - erestum - Jan-13-2021

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")



RE: Conditional - bowlofred - Jan-13-2021

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"]:



RE: Conditional - erestum - Jan-13-2021

(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"]:



RE: Conditional - erestum - Jan-13-2021

Thank you!!!