Coffee Chatbot

Could anyone provide me some insight on this error.
When I run the code in vscode it works as expected but in code academy I seem to get this error regardless of the letter of input ( a, b, c)

Thank you

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'
   

def coffee_bot():
  print("Welcome to the cafe!")
  size = get_size()
  print("your size is " + str(size))

coffee_bot()
Traceback (most recent call last):
  File "script.py", line 18, in <module>
    coffee_bot()
  File "script.py", line 15, in coffee_bot
    size = get_size()
  File "script.py", line 2, in get_size
    res = input("What size drink can I get for you? \n[a] Small \n[b] Medium \n[c] Large \n> ")
  File "<string>", line 1, in <module>
NameError: name 'a' is not defined

That’s weird. This is in the Python shell…

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

What size drink can I get for you?
[a] Small
[b] Medium
[c] Large
> a
>>> 

Yea @mtf that’s exactly what stumps me
So I can not progress because of this

** Update **

So I believe I found the error this morning. I was running the script with


python script.py

which was creating the error

when I run the script with


python3 script.py 

I no longer get the name space error

Hopefully this helps someone else :slight_smile:

2 Likes