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("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
<p>This isn't an AI. This is hard-coded.</p>
<p>Actually agree... =T</p><p>AI is a far more complicated subject.... </p><p>Take a look at this:</p><p><a href="http://letzgro.net/blog/creating-ai-using-python/" rel="nofollow">http://letzgro.net/blog/creating-ai-using-python/</a></p><p>=)</p>
<p>I think you dont know what actually AI is</p>
<p>your all melons</p>
<p>cool </p>
<p>This is a decent beginner tutorial. But, you should of used &quot;if userinput == &quot;hi&quot;.lower(): # do stuff &quot; its less work. If you wanted to use a list what I would of done is&quot;input = [&quot;hi&quot;] if userinput.lower() in input: # do code&quot;</p>
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
<p>That is kinda cool but you should look into something like pyymal or nltk. But its cool :)</p>
<p>Also, this isn't what I'd consider an A.I. </p>
<p>It's a very nice program for beginners, but I have to say, if you don't know anything about python, please don't try making any AI program, and then fill the comments section with questions that have an obvious answer. Codecademy has a great python tutorial, for Python 2.7. The program here is in python 3, but changes are minor(print became a function and raw_input does not exist, and some other that are more advanced). Anyways, that's all I had to say, so please take some time and learn the language if you are really interested.</p>
generally people prefer Python 2.7 due to it having more compatible external libraries. However I personally prefer Python 3 as I started learning the language a few months after the release of it. the main differences to basic Python is using raw_input instead of input in Python 2 and the difference in syntax with the print command
<p>Neither of the codes are working for me. The console says</p><p>&gt;&gt;&gt; hi</p><p>Traceback (most recent call last):</p><p>File &quot;Monty1.py&quot;, line 2, in &lt;module&gt;</p><p>NameError: name 'hi' is not defined</p><p>Press any key to continue...</p>
<p>Change the &quot; userInput = input(&quot;&gt;&gt;&gt; &quot;) &quot; line to &quot; userInput = str(input(&quot;&gt;&gt;&gt; &quot;)) &quot;</p><p>This will make the user input a string, and it will be accepted. Otherwise python thinks that you asked for a variable. </p>
Also, make sure your using 'raw_input' and not just 'input'.
my friend, this is a python 3 tutorial so raw_input does not exist
Male sure 'Hi' is in quotations. It needs to be a string...
<p>while True:</p><p>---&gt;userInput = raw_input('&gt;&gt;&gt; ')</p><p>---&gt;if userInput.lower() in ['hi', 'hello', 'good morning', 'good evening']:</p><p>---&gt;---&gt;print ('Hello there')</p><p>---&gt;---&gt;break</p><p>---&gt;else:</p><p>---&gt;---&gt;print (userInput.lower(), type(userInput))</p><p>---&gt; = single indent</p><p>---&gt;---&gt; = double indent</p>
<p>none of these worked for me</p>
by none of them do you mean none of the tutorials
<p>its a great instructable, however, for the python beginners like myself.....is there a version without pseudocode? that stuff works when you know how to implement a feature, and if you're the kind of person that learns from things that are already built. its an extra 3 hours :) cool idea though, i always thought that if statements were the center of an ai<br><br>i think....you used a while command to give the if a condition?</p>
He used the 'while' statement to cause the program to repeatedly ask for input over and over again.
<p>that is true, i learn most code by copy pasting and seeing how its laid out.</p><p>python is, a bit weird in that if you copy paste, it doesn't always follow the white-space, and i still sometimes forget what to use. and where.</p><p>my mistake :)</p>
copying and pasting is the worst way to learn as your brain is not actually interpreting what you do, if you wish to begin learning Python I would recommend investing in this book: http://www.amazon.co.uk/Python-Programming-Absolute-Beginner-Dawson/dp/1435455002 it's what first got me into programming. I was planning on stopping the Python tutorial series but I may start it up again to give you a hand with learning it
I think you may be confused about what pseudocode is. pseudocode is writing out what you are planning to do pretty much in plain English which basic Python, as it is such a high level language, is already very similar to
<p>That is a good start. Here is my 2 cents for the friends who are using Python 2.X. Use the function 'raw_input' instead of 'input'. </p><p>'input' evaluates the user input to give a result. If the input is syntactically wrong it can not be evaluated so it gives an error message. </p><p>eg. </p><p>userInput = input('&gt;&gt;&gt; ') </p><p> print userInput</p><p>Execute the above two lines of code. </p><p>Trial 1</p><p>&gt;&gt;&gt;1+2 (this is a user input)</p><p>3 (the user input was evaluated to produce this result)</p><p>Trial 2</p><p>&gt;&gt;&gt;hi (this is another user input, which is syntactically wrong for python)</p><p>Traceback (most recent call last): </p><p> File &quot;&lt;pyshell#5&gt;&quot;, line 1, in &lt;module&gt;</p><p> input(hi)</p><p>NameError: name 'hi' is not defined (the error message the user gets)</p><p>Read more about 'input' here <a href="https://docs.python.org/2/library/functions.html#input" rel="nofollow">https://docs.python.org/2/library/functions.html#i...</a> </p><p>Now the alternate version of this instructable is here.</p><p>while True:</p><p>---&gt;userInput = raw_input('&gt;&gt;&gt; ')</p><p>---&gt;if userInput.lower() in ['hi', 'hello', 'good morning', 'good evening']:</p><p>---&gt;---&gt;print ('Hello there')</p><p>---&gt;---&gt;break</p><p>---&gt;else:</p><p>---&gt;---&gt;print (userInput.lower(), type(userInput))</p><p>---&gt; = single indent</p><p>---&gt;---&gt; = double indent</p>
<p>This would keep going over and over as the while loop in never broken. To fix this try:</p><br><p>while True:<br>---userInput = input(&quot;&gt;&gt;&gt; &quot;)<br>---if userInput in ['hi', 'HI', 'Hi']:<br>------print(&quot;Hello&quot;)</p><p>------break<br>---else:<br>------print(&quot;I did not understand what you said&quot;)</p>
<p>that's the idea...</p>

About This Instructable




Bio: 1 new python tutorial every day Comment what you want the next one to be Please favourite and subscribe Notice Board: - since instructables has automatically ... More »
More by BlueBlood Studios:Teach Me Python #7: Control Statements Pt.2: While Loops Teach My Python #6: Control Statements Pt.1: If, Else And Elif Teach Me Python #5: Simple Maths 
Add instructable to: