-2

After I did the code below I checked if it worked. The problem was that whatever I typed it always shows the response of 'if' even if I changed the response

I tried changing positions and responses but nothing worked

hello = input ("Hello there! \n My name is PIM. \n It `enter code here` stands for Primary Interactive Machine. \n What is your name?")
print ("Nice to meet you," + hello)
ans1 = input ("Can I ask you a question? <yes/no>")
if (ans1 == 'yes',' yes')                              
    ans2 = input ("Which color do you prefer? <blue/pink>")
elif(ans1 == 'no',' no'):
    print ("Well then, we will just stay in silence")
else:
    print ("I will not talk to someone who doesn't care about me. \n You had one simple job, choose yes or no and even then, you failed.")

It is expected to reply accordingly to the response but instead, it only sends the 'if' reply

pppery
  • 3,731
  • 22
  • 33
  • 46
  • Hi. I didn't know that `if (ans1 == 'yes',' yes'):` was a valid python code, and I suspect it means `if ((ans1 == 'yes') or (' yes')):` and the truthy value of ' yes' is always `True`. Change it to `if(ans1 == 'yes' or ans1 == ' yes'):` or to `if (ans1 in ['yes', ' yes]):` – Aryerez Sep 08 '19 at 17:59
  • @Aryerez It doesn't mean `or`. It's simply a *tuple*. A *non-empty tuple*. Which will always be truthy. – deceze Sep 09 '19 at 07:03
  • @deceze Tnx for the clarification :) – Aryerez Sep 09 '19 at 07:33

1 Answers1

0

Try this:

if ans1 in( 'yes' , ' yes'):                             
    ans2 = input ("Which color do you prefer? <blue/pink>")
elif ans1 in( 'no' or ' no'):
    print ("Well then, we will just stay in silence")
else:
    print ("I will not talk to someone who doesn't care about me. \n You had one simple job, choose yes or no and even then, you failed.")
misguided
  • 3,699
  • 21
  • 54
  • 96