Chatbot Code returning desired output and "none"

Hello!

I working on the Coffee Chatbot exercise:Coffee Chatbot

I’m getting both the desired output and the word “None”
I can’t figure out where it’s coming from.
Can someone help?

Current Result: $ python3 script.py
Welcome to the cafe!
What size drink can I get for you?
[a] Small
[b] Medium
[c] Large

b
What type of drink would you like?
[a] Brewed Coffee
[b] Mocha
[c] Latte
c
What type of latte would you like
[a] latte
[b] non-fat latte
[c] soy latte
b
Alright, that’s a Medium Non-Fat Latte!
None <=== RIGHT HERE (Why is it happening?)
Can I get your name please?
jen
Thanks jen! Your drink will be out shortly
$

Code:

Define your functions

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

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:
print_message()
return 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 order_latte()
else:
print_message()
return get_drink_type()

def order_latte():
res = input(“What type of latte would you like \n[a] latte \n[b] non-fat latte \n[c] soy latte \n>”)
if res == “a”:
return “Latte”
elif res == “b”:
return “Non-Fat Latte”
elif res == “c”:
return “Soy Latte”
else:
print_message()
return order_latte()

def coffee_bot():
print(“Welcome to the cafe!”)
size = get_size()
drink_type = get_drink_type()
print(‘Alright, that's a {} {}!’.format(size, drink_type))

print(coffee_bot())

name = input(“Can I get your name please?”)
print(“Thanks {}! Your drink will be out shortly”.format(name))

Please format your code so people can you help debug it.

That said, take a look at how you’re using print() when you should be using return in your functions. In general, one shouldn’t use print to return information. Functions take input and return something.
print() is not the same as a return statement. A return will exit a function and return a value back to the caller. The print() function writes or prints a string.

Specifically, take a look at the last function.

2 Likes

Apologies for the bad formatting (first time posting).

I adjusted the print statements to return and it worked!

Thank you!

1 Like