Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Farouk Charkas
Farouk Charkas
1,957 Points

How do I do this? I would appreciate any feedback!

Now I am making an AI script with a feelings feature. But I would enter "You Stupid" and it would reply "I did not understand that". Here is my code:

elif userInput in ['You'] and ['stupid']:
           print "That is mean! I am ending this conversation!"
           #I deleted the feelings script below

How do I make it check for 'You' and 'stupid'

2 Answers

Okay so I think I know how to do this.

user_input = userInput.split() #splitting the input into a list

for word in user_input:
  if word == "You" or word == "you" or word == "Stupid" or word == "stupid":    #You could convert the user input into all lowercase here if you wanted
    print "That is mean! I am ending this conversation!"
    break #so if the user enters you AND stupid, it won't repeat "That is mean! I am ending this conversation!"
Farouk Charkas
Farouk Charkas
1,957 Points

Reasonable, how do I set all letters to lowercase?

So this would be the complete code. I also cleaned it up a bit. Just ask if you need anymore help.

userInput = userInput.lower().split()

for word in userInput:
  if (word == "you") or (word == "stupid"):
    print ("That is mean! I am ending this conversation!")
    break

I think you want:

elif userInput == "You Stupid":
           print "That is mean! I am ending this conversation!"
           #I deleted the feelings script below
Farouk Charkas
Farouk Charkas
1,957 Points

No I would like it to make it only check for you stupid, like it will also accept You are so stupid