Coffeebot project - Name Error

Hi all,

I have a question about the chatbot exercise in python. With the following code I get a NameError and do not understand why.


def coffee_bot():
    print('Welcome to the cafe!')
    size = get_size()
    print(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'

coffee_bot() 


That should work, maybe you guys get why it does not. I have no idea, to me it looks fine and exactly like the hints and examples in the exercise.
Thanks for the help and happy coding!

A little more of the error code would be helpful. Which name is causing the issue?
It’d also be worth having a little look through the following especially since indentation is so important in Python-

Ah, great. Thanks for the info on formatting!
The error comes up after the user input. Say, the user types ‘a’ , then the error will throw, that ‘a’ was not defined.

Ah this one will differ a little on Python3 and Python2. Have a look at the difference between raw_input and input in python2. If you want user input to be treated as a string use raw_input-

https://docs.python.org/2/library/functions.html#input
https://docs.python.org/2/library/functions.html#raw_input

Well, that does not work, it is a Python3 script.

Are you calling it with a version of Python3? I just tried a direct copy/paste of your original code and it ran as you expect in Python3 but with version 2 throws a name error because of the difference between raw_input and input.

I am calling it in the codeacademy shell:

??
changed it back to input again and now it suddenly works.
?
I still don’t get, what went wrong in the beginning.
Anyway, thanks a lot for the help!