I’m currently working my way through the chatbot path after completing the Python3 path. On the coffee chatbot project it asks to take a size for a drink, and if an invalid response is given to run the get_size() function again. This is the code I have for it, that does appear to be correct based on the hints given at the side:
def coffee_bot(): print('Welcome to the cafe!') size = get_size() print(size) def get_size(): res = input("What size drink can I get 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: get_size()
The problem is when the recursion is used. If a valid answer is given immediately, it will return the correct size (i.e. small, medium or large). However, if an invalid letter is given and the function runs again, any later, including a b c is returning None. I can’t figure out why the is so would look any advice! There is nothing in the steps or hints that suggests this should be happening!