Type error Build Chatbots with Python; Coffee Chatbot project

Hi,

I’m currently going through the ‘Coffee Chatbot’ project in the ‘Build Chatbots with Python’ skill path. I’m running into an Type Error I can’t quite understand:

Welcome to the cafe!
What size drink can I get for you? 
[a] Small 
[b] Medium 
[c] Large 
> a
small
what type of drink would you like? 
[a] Brewed coffee 
[b] Mocha 
[c] Latte 
d
I'm sorry, I did not understand your selection. Please enter the corresponding letter for your response.
what type of drink would you like? 
[a] Brewed coffee 
[b] Mocha 
[c] Latte 
a
Traceback (most recent call last):
  File "script.py", line 37, in <module>
    coffee_bot()
  File "script.py", line 7, in coffee_bot
    drink_type = get_drink_type()
  File "script.py", line 30, in get_drink_type
    return print_message() + get_drink_type()
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
$ 

So if I choose the correct letter, I get the response I expect. If I choose a letter that isn’t an option it asks me to enter a corresponding letter, as expected. But if I enter a letter that isn’t an option, and afterwards enter a letter that is an option I get this Type Error. I hope someone can help me understand this.

def coffee_bot():
  print("Welcome to the cafe!")
  size = get_size()
  print(size)
  drink_type = get_drink_type()
  print(drink_type)
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'
  else:
    return print_message() + get_size() 

def get_drink_type():
  res = input("what type of drink would you like? \n[a] Brewed coffee \n[b] Mocha \n[c] Latte \n")
  if res == "a":
    return "Brewed coffee"
  elif res == "b":
    return "Mocha"
  elif res == "c":
    return "Latte"
  else:
    return print_message() + get_drink_type()

def print_message():
  print("I'm sorry, I did not understand your selection. Please enter the corresponding letter for your response.")

This is my code ^^
I’m sorry if this has already been posted, but I couldn’t find anything.

Your print_message function implicitly returns None That is what the error message is telling you.

2 Likes