0

I'm trying to output a specific answer based on the users input, the code works now, but only for one word answers. Im trying to achieve the same output but the user must enter a full sentence containing the assigned words. Keep in mind I have to use the split() function.

My code:

def welcome():
    print('Welcome to the automated technical support system.')
    print('Please describe your problem.')
# *************************************
def get_input():
  return input().lower()

# *************************************
def main():

    welcome()  
    while True:
      query = get_input() 
      if query == 'crashed':
        print("Are the drivers up to date?")

      elif query == 'blue': 
        print("Ah, the blue screen of death. And then what happened?")

      elif query == 'hacked':
        print("You should consider installing anti-virus software.")

      elif query == 'bluetooth':
        print("Have you tried mouthwash?")

      elif query == 'windows':
        print("Ah, i think i see your problem. What version?")

      elif query == 'apple':
        print("You do mean the computer kind?")

      elif query == 'spam':
        print("You Should see if your mail client can filter")

      elif query == 'connection':
        print("Contact Telkom.")


      elif not query=='quit':
        print('Curious, tell me more.')

      elif query == 'quit':
        break  

main()   
# ************************************* 

Sample Output:

Welcome to the automated technical support system.
Please describe your problem.

>>crashed
Are the drivers up to date?
>>yes
Curious, tell me more.

Output I need:

Welcome to the automated technical support system.
Please describe your problem.

>> my pc crashed
Are the drivers up to date?
>>yes
Curious, tell me more.
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • Does this answer your question? [Does Python have a string 'contains' substring method?](https://stackoverflow.com/questions/3437059/does-python-have-a-string-contains-substring-method) – mkrieger1 Jun 19 '20 at 14:18

3 Answers3

0

This may be what you're looking for:

if 'crashed' in query:
    # Do stuff
Adam Boinet
  • 521
  • 8
  • 22
0

At the place where you are using '==' in your if statement you can use 'in' keyword so you can get answer even you write this: Crashed hope you understand and will be helpful cya.

0

You can achive this by looking the keyword in query string. There are multiple ways to check the substring in python.

if 'crashed' in query:
    # your logic
elif 'blue' in query:
   # your logic
...

For more details about other options you can check https://stackabuse.com/python-check-if-string-contains-substring/

Durga M
  • 534
  • 5
  • 17