0

This code should be printing "I am unit Alpha 07" when the user says something like "what's your name", but for some reason the if statement never returns true. Please help!

import difflib
    while True:
     talk = input("Please say something > ")
     temp = (difflib.get_close_matches(talk, ['What is your name?', 'Hello', 'peach', 'puppy'],1,0.2))
     print(temp)
     if temp == "['What is your name?']":
      print("I am unit Alpha 07")
      break
     continue

    input()

Here's a screenshot

Sorry if this is really stupid.

1 Answers1

0

Since temp is a list and you want to check if the first element of that list is What is your name? then you can't just do it all as a string as in put it like "['What is your name?']" as you have done, you need to check the first element (index 0) and then compare this:

if temp[0] == "What is your name?":
    ...

And this will work. Good luck!

Joe Iddon
  • 20,101
  • 7
  • 33
  • 54