Python bot

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gloomer
    New Member
    • Apr 2007
    • 13

    Python bot

    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.
  • ghostdog74
    Recognized Expert Contributor
    • Apr 2006
    • 511

    #2
    to get input from user , use raw_input().

    Comment

    • ilikepython
      Recognized Expert Contributor
      • Feb 2007
      • 844

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

      Code:
      x = raw_input("Enter text you wish to display here")
      
      if x == "hi":                      #use an if....elif.....else     block
          print "Hi"
      elif x == "bye":
          print "see you"
      else:
          print "did not understand what you said"
      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?

      Comment

      • gloomer
        New Member
        • Apr 2007
        • 13

        #4
        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

        Comment

        • uyuyuy99
          New Member
          • Jul 2009
          • 1

          #5
          Originally posted by gloomer
          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.

          Comment

          Working...