Real Python AI

3,484

34

10

Introduction: Real Python AI

this is is an instructable that will teach you how to make a python AI.(for real!!!!!!!!!!!)

Step 1: Programing Your AI

here is how to make him. first you have to import random then add different speech categories. like greetings or questions. later you can add categories to your software but for now you will have three. then put while True:

userinput = raw_input is very important so it takes what you put in and only what you put in. The rest is simple, all that you have to do is put: if userInput in greetings:

random_greetings = random.choice(greetings)

print(random_greeting)

to do the other stuff like the questions, all that you have to do is put elif instead of if.

if you are confused the picture at the top might help you.

Be the First to Share

    Recommendations

    • Mason Jar Speed Challenge

      Mason Jar Speed Challenge
    • Bikes Challenge

      Bikes Challenge
    • Remix Contest

      Remix Contest

    10 Discussions

    0
    T-M-L1019
    T-M-L1019

    Question 1 year ago

    i have typed out the above, im just stuck at how can i actually ask the questions

    0
    JoshuaV50
    JoshuaV50

    2 years ago

    how can I apply this into a simple AI

    0
    killer-queen
    killer-queen

    3 years ago

    what version of python is this?

    0
    RishiR31
    RishiR31

    Reply 3 years ago

    I think they've used Python 2.7. In 3.5, the method to take user input is input() rather than raw_input().

    1
    Jpool151
    Jpool151

    3 years ago

    This is so cool.

    import random

    greetings = ['hola','hello','hi','Hi','hey!','hey','sup','whats up?',]

    questions = ['how are you?','how are you doing?']

    responses = ['Okay',"I'm fine" 'i am great!']

    while True:

    userInput = raw_input(">>> ")

    if userInput in greetings:

    random_greetings = random.choice(greetings)

    print(random_greeting)

    elif userInput in question:

    random_response = random.choice(responses)

    print(random_response)

    else :

    print("I did not understand what you said")

    1
    hywile
    hywile

    4 years ago

    Basic, but I like it; it's good to get you started in the right direction.

    0
    bornozz
    bornozz

    4 years ago

    it is very basic but i feel some times you need basics to get people to want to do it.

    so what would you like your next step to be build a dictionary of question you can ask with a talking reply and a run bash or shell script to do things like open web sits ect...

    0
    samarthagi
    samarthagi

    4 years ago

    this is immensly basic. The most basic python algorithm that you can call AI would be tic tac toe or a ping pong game.