Jump to content

How to define raw_input method?

Featured Replies

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.

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.

 

  • Author

Hi,

Thanks a lot.

 

I thought raw_input(..) is a user-defined function. Thanks it worked by changing raw_input(...) to input(...).

Zulfi.

Archived

This topic is now archived and is closed to further replies.

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.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.