Jump to content

How to define raw_input method?


zak100

Recommended Posts

import pickle,random

a=open('lexicon-luke','rb')

successorlist=pickle.load(a)

a.close()

def nextword(a):

   if a in successorlist:

      return random.choice(successorlist[a])

   else:

      return 'the'

speech=''

while speech!='quit':

   speech=raw_input('>')

   s=random.choice(speech.split())

   response=''

   while True:

      neword=nextword(s)

      response+=' '+neword

      s=neword

      if neword[-1] in ',?!.':

         break

   print (response)
  

Hi,

I got the above code from:

https://stackoverflow.com/questions/5306729/how-do-markov-chain-chatbots-work

I am getting following error:


 

Quote

Traceback (most recent call last):
  File "/home/zulfi/PycharmProjects/chatbot/MarkovBot.py", line 13, in <module>
    speech=raw_input('>')
NameError: name 'raw_input' is not defined

Somebody please guide me how to define raw_input(...)?

Zulfi.

Link to comment
Share on other sites

You should be well aware by now, after months spend on writing Python, how to solve such basic issues..

Simply enter error or warning message in e.g. Google search engine.. e.g.

https://www.google.com/search?q=NameError%3A+name+'raw_input'+is+not+defined

and we see the list of people who had exactly the same issue as you in the past.

Write it down: use Google search engine.

That's what programmers do all day long.

Immediately you have answers, without having to wait until somebody will answer your question on the forum here.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.