Python coffee chatbot

# Define your functions
def coffee_bot():
  print("Welcome to the cafe!")
  size = get_size()

def get_size():
   res = input("What size drink can I get for you? \n[a] Small \n[b] Medium \n[c] Large \n> ")

   if res == 'a':
     return 'small'
   elif res == 'b':
      return 'medium'
   elif res == 'c':
      return 'large'

# Call coffee_bot()!

when I enter an input (say ,a) then it gives me an error
Traceback (most recent call last):
File “”, line 20, in
File “”, line 4, in coffee_bot
size = get_size()
File “”, line 8, in get_size
res = input("What size drink can I get for you? \n[a] Small \n[b] Medium \n[c] Large \n> ")
File “”, line 1, in
NameError: name ‘a’ is not defined

Someone please help me!

I tried your code on my local env but I didn’t got any errors. Can you please share the screenshot of when ou get this error (Including the image of your code and error displayed in terminal on website).
I will only be able to assist you further after that.


Dude literally I don’t know what’s the problem here because I ran this code both at codecademy and offline on my computer but it’s working completely fine. One thing I notice here is return statements in both elif are a little more indented, but that’s definitely not the problem which is causing this error. I suggest you report bug in here. This might be some internal problem with the online code editor at codecademy.

This seems likely to be an issue with Python2 compared to Python3. Note that the function input() differs between the two-

If you’re limited to using Python2 consider using the raw_input() function when dealing with user input.

This could be a possible problem but in this project Python 3 is used. I’ve done this project in Build Chatbots with Python skill path.

Some of these projects appear to use Python 3, however they actually compile using Python 2. In Python 2, input() is still a function, however it does not automatically convert to string like raw_input() does. Here is some reading on the matter.


In that case, this would be the most appropriate reason for this error. But why didn’t this happen with anyone else? :thinking: :thinking:

This is happening because they are using python in the bash terminal instead of python3 Try running with with python3 instead and you shouldn’t get any errors.


yes actually i was styping python in the terminal I didn’t knew that you have to explicitly define python3.
Thanks everybody

You’ll have to specify python3 in the bash terminal at codecademy. But python will work in terminal of your pc.

Good you got the solution!

1 Like

I’ve been having trouble with the chatbot. whenever I put in a value for the size of the coffee, It gives the else message. the coffee type code works fine and that is based off of the size code. here’s the code.please help
#Define your functions
bot_greeting = “welcome to the cafe!”
res = ‘’
res_2 = ‘’
def print_message():
print(‘I’m sorry, I did not understand your selection. Please enter corresponding letter for your response.’)
def get_size():
res = input('What sized drink do you want? \n[a] small \n[b] medium \n[c] large \n> ')
size = get_size()
if res == ‘a’:
elif res == ‘b’:
elif res == ‘c’:
def get_drink_type():
res_2 = input('what beverage would you like? \n [a] brewed coffee \n[b] mocha \n[c] latte \n> ')
if res_2 == ‘a’:
print(‘brewed coffee’)
elif res_2 == ‘b’:
elif res_2 == ‘c’: