How to Make a Python Conversation
As a scripting language that works across all operating systems and web browsers, Python can be used to create automated responses to user inputs. Using this method and language, you can make conversations between the user and the computer. If a user enters a sentence, the Python script can output a matching reply based on what the user set as an input.
Instructions
-
-
1
Launch a plain text editor like Microsoft's Notepad, which is bundled with Windows, or TextEdit, which is bundled with Apple's Mac OS X.
-
2
Insert a name and raw input variable to define the input that the user makes to initiate a response from the Python script along with what the associated output is:
name = raw_input("Hi \n")
print "Hello",user -
-
3
Include optional or variable responses to inputs by creating an argument in the Python conversation script:
feeling = raw_input("How are you doing? A: Great, B: Good, C: Okay \n")
if feeling.good() == "A" :
print <response A>
elif feeling.good() == "B" :
print <response B>
elif.feeling.good() =="C" :
print <response C>
else:
print <You didn't make a choice> -
4
Save the Python code as a text file and then paste the script into a Python application to which you wish to add a conversation bot or execute it on its own by uploading it to a web server where you can access it.
-
1