Connecting Tech Pros Worldwide Help | Site Map

Python bot

Newbie
 
Join Date: Apr 2007
Posts: 13
#1: Apr 3 '07
Hey guys, I've really got into python, but I'm still noobish at it.

I have an idea how my Python bot would work. But I can't find the right python code for it.


print "Hi,i'm a bot"
if input == hi
print "Hi yourself"
else:

print "I don't know what you just said"



I know it's something along the lines of that. But "input" doesn't exist. I need to be able to grab the user's input and match it up against "hi".

Since this will be a simply bot. I'll just make 30 or so "statements" that the person can type in and get a response.

Such as "Why is the sky blue" Bot response: Because blah blah blah scientific explanation.

I know this isn't the right type of code. I have the right idea, but I'm not sure how to do this exactly.
Expert
 
Join Date: Apr 2006
Posts: 512
#2: Apr 4 '07

re: Python bot


to get input from user , use raw_input().
ilikepython's Avatar
Expert
 
Join Date: Feb 2007
Posts: 839
#3: Apr 4 '07

re: Python bot


also if you want to match it with a string you have to put it in quotes like this:

Expand|Select|Wrap|Line Numbers
  1. x = raw_input("Enter text you wish to display here")
  2.  
  3. if x == "hi":                      #use an if....elif.....else     block
  4.     print "Hi"
  5. elif x == "bye":
  6.     print "see you"
  7. else:
  8.     print "did not understand what you said"
  9.  
Also, you can use a while loop to keep coming back to the raw_input statement thus replaying the if block or whatever you may want to put. Does that help?
Newbie
 
Join Date: Apr 2007
Posts: 13
#4: Apr 5 '07

re: Python bot


Oh that helps a lot. But do I always have to use raw_input? I may not want a text box popping up each time.

Is there any way to use just a regular input function?

Thanks
uyuyuy99's Avatar
Newbie
 
Join Date: Jul 2009
Posts: 1
#5: Jul 9 '09

re: Python bot


Quote:

Originally Posted by gloomer View Post

Oh that helps a lot. But do I always have to use raw_input? I may not want a text box popping up each time.

Is there any way to use just a regular input function?

Thanks

There is no text box (besides the console window) that pops up.
Reply