Loop Coffee Chatbot

Hello, I am trying to do the bonus tasks on Codecademy.

    • Allow the chatbot to recognize additional inputs besides 'y' and 'n' – such as 'yes' , 'sure' , or 'nah' – when it asks the user if they would like another drink
  1. Allow the chatbot to recognize key exit words such as 'stop' or 'bye' that can terminate the order at any step.
    And it’s not working. Here is the code that I wrote. Any help is appreciated! Thank you.
from utils import print_message, get_size, order_latte def coffee_bot(): print('Welcome to the cafe!') order_drink = 'y' drinks=[] if input== 'stop' or 'bye': break while order_drink == 'y': size = get_size() drink_type = get_drink_type() drink = '{} {}'.format(size, drink_type) print('Alright, that\'s a {}!'.format(drink)) drinks.append(drink) #Allow the chatbot to recognize additional inputs besides 'y' while True: order_drink=input('Would you like to order another drink? (y/n)\n') if order_drink in ['yes', 'yeah', 'sure', 'yup']: order_drink = 'y' elif order_drink in ['nope', 'nah', 'no']: order_drink = 'n' if order_drink in ['y', 'n']: break print("Okay, so I have:") for drink in drinks: print('-',drink) name = input('Can I get your name please? \n> ') print('Thanks, {}! Your order will be ready shortly.'.format(name)) 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 order_mocha() elif res == 'c': return order_latte() else: print_message() return get_drink_type() # Define new functions here! def order_mocha(): while True: res = input("Would you like to try our limited-edition peppermint mocha? \n[a] Sure! \n[b] Maybe next time!\n>") if res=="a": return "peppermint mocha" elif res=="b": return 'mocha' print_message() coffee_bot()

Re your part 2.
input would need brackets for it to work - i.e. if input() == …
secondly break is for leaving a loop. return may work better.

I’m not sure you’ve positioned it right, either. What I think it’s suggesting is that you check for ‘stop’ and ‘bye’ each time the user inputs something.
You could do this by adding extra elif statements or adding in a little function.

Thank for your reply! I’ve added elif statements to each case for a break in the loop but it says that my break is outside of the loop and doens’t execute my code.

from utils import print_message, get_size, order_latte def coffee_bot(): print('Welcome to the cafe!') order_drink = 'y' drinks=[] while order_drink == 'y': size = get_size() drink_type = get_drink_type() drink = '{} {}'.format(size, drink_type) print('Alright, that\'s a {}!'.format(drink)) drinks.append(drink) #Allow the chatbot to recognize additional inputs besides 'y' while True: order_drink=input('Would you like to order another drink? (y/n)\n') if order_drink in ['yes', 'yeah', 'sure', 'yup']: order_drink = 'y' elif order_drink in ['nope', 'nah', 'no']: order_drink = 'n' elif order_drink in ['stop', 'bye']: break if order_drink in ['y', 'n']: break print("Okay, so I have:") for drink in drinks: print('-',drink) name = input('Can I get your name please? \n> ') print('Thanks, {}! Your order will be ready shortly.'.format(name)) 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 order_mocha() elif res == 'c': return order_latte() elif res == 'stop' or 'bye': break else: print_message() return get_drink_type() # Define new functions here! def order_mocha(): while True: res = input("Would you like to try our limited-edition peppermint mocha? \n[a] Sure! \n[b] Maybe next time!\n>") if res=="a": return "peppermint mocha" elif res=="b": return 'mocha' elif res == 'stop' or 'bye': break print_message() coffee_bot()

break will only exit you out a loop, not an if statement. There’s no loop in get_drink_type for it to break out of.