python - Why is my string recognition algorithm not detecting the correct string? -


apparently, string recognition algorithm not working properly. returning wrong responses based on user's input. know it's simple, can't see right now. done research , haven't found python issue here when user input entered, wrong response returned. if statements formed? there issue string search?

import random  def po_response(): response = {1 : 'this random response po_response()',             2 : 'this random response b po_response()',             3 : 'this randomw response c po_response()'} answer = random.sample(response.items(),1) print(answer) main()   def greetings_response(): response = {1 : 'this response greetings_response()',             2 : 'this response b greetings_response()',             3 : 'this response c greetings_response()'} answer = random.sample(response.items(),1) print(answer) return response main()   def main(): userrequest = input('welcome, please enter request. \n') userreq = userrequest.lower() if 'how you' or 'how\'s going' in userreq:     print('first if')     print('the value of input ')     print(userreq)     greetings_response()   elif 'ship' + 'po' or 'purchase order' in userreq:     print('elif')     print('the value of input ')     print(userreq)     po_response()   else:     print('please re-enter request')  main()  

here response when enter 'ship po'

   welcome, please enter request.     >>>ship po    first if    value of input     ship po    [(2, 'this response b greetings_response()')]  

it should not go greetings_response() function, should go po_response() function. not sure why it's acting way.

test using or seems wrong. maybe meant if ('how you' in userreq) or ('how\'s goind' in userreq) ? have python operators precedence.


Comments