Python Tutorials: Creating a Simple Python AI

64,072

18

38

Posted

Introduction: Python Tutorials: Creating a Simple Python AI

Step 1: The Code

After opening a blank python file, type the following code:

--- = tab

while True:
---userInput = input(">>> ")
---if userInput in ['hi', 'HI', 'Hi']:
------print("Hello")
---else:
------print("I did not understand what you said")



This can be extended with elif statements and eventually you will eventually have your very own slightly clever AI. Just make sure that the else statement is always at the bottom of your code

Share

    Recommendations

    • Microcontroller Contest

      Microcontroller Contest
    • Science of Cooking

      Science of Cooking
    • Pocket-Sized Contest

      Pocket-Sized Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    32 Comments

    Is this AI programming?...not even basic :)

    This is a pretty simple starting example that can be used for beginning programmers who probably haven't created a single line of code and want to get into AI programming. Of course it is hardcoded but I'd place that under the weakest of AI because simply put, AI is fake intelligence. The whole point is to simulate some kind of intelligence that we humans portray when we communicate. It's diificult to get a computer with no built in and innate sense of common sense or consciousness to actually when attain those traits. We are humans, not freaking gods or mother nature. But we've come pretty far in AI and I hope we can get even farther even with the protests of the supposed "dangers of AI".

    This isn't an AI. This is hard-coded.

    I think you dont know what actually AI is

    This is a decent beginner tutorial. But, you should of used "if userinput == "hi".lower(): # do stuff " its less work. If you wanted to use a list what I would of done is"input = ["hi"] if userinput.lower() in input: # do code"

    this is an oldish tutorial, I had not realised .lower() existed in the syntax of Python. As for your other comment, this isn't an AI since it's not learning anything. it's more about giving people an idea of how to use if statements and if else, etc. I have a more advanced version of an AI here: https://www.pythonanywhere.com/shared_console/83e3371d-bbfa-4f66-9ccd-3cd0372f5b17 this one learns from what the user types in. This one technically qualifies as an AI as it learns from what the user types in. it also has the ability to create opinions of you ask it an opinion (e.g if you ask it a question like 'do you like chocolate?' it will generate an opinion and that opinion will stay the same) I did plan to advertise this version more and see if I could get many people to use it, therefore speeding up the learning process