-1

I am just learning python, and have written the beginning of a simple program that asks for some information.

I want to include some additional logic at the end depending on the user input but can't seem to get it right.

Any help is greatly appreciated!

Here is what I have written, but no matter the user input, it just prints the first "move to next step"

Yes, yes, no, No are all defined variables

#######################################################


#Program response

if (yes or Yes in (answer_str)): print('Congrats! Move to next step')

elif (no or No in (answer_str)): print ('Ok we need to start over')

DB48
  • 27
  • 1
  • 1
    Can you format your code? Also in Python `else if` is written as `elif`. – arsho May 29 '22 at 16:58
  • 1
    And `if`, `elif`, and `else` have an expression, and then a `:`. – Chris May 29 '22 at 16:58
  • https://imgur.com/a/U9qEyxx not sure how this syntax works but I think it works differently from what you expect. You probably want `'yes' in ans or 'Yes' in ans` – Louisb Boucquet May 29 '22 at 17:05
  • `if ('yes' or 'Yes' ) in (answer_str)` is wrong. Either use `if 'yes' in answer_str or 'Yes' in answer_str` or use `any()` – kuro May 29 '22 at 17:06
  • I updated, but just runs the first print, regardless of user input – DB48 May 29 '22 at 17:16
  • Just do `if answer_str.lower() == "yes"` so you don't need to test against two different things. Or `if answer_str.lower().startswith("y")` if you want it to accept "y", "yeah", "yup", etc. – Samwise May 29 '22 at 17:33
  • https://replit.com/@DB48/UntitledPython#main.py – DB48 May 29 '22 at 17:47
  • 1
    @Samwise, watch out for "ye... no." – Chris May 29 '22 at 19:04
  • there's also the infamous "yeah right", bane of natural language processing algorithms everywhere – Samwise May 30 '22 at 13:48

0 Answers0