Pizzabot

Artificial Intelligence (AI) can be defined as the ability of a digital computer to perform tasks normally requiring human intelligence, like visual perception, speech recognition or chatting. A chatbot is a piece of software that may use AI and can interact with humans and keep a basic chat or conversation, very useful in companies to automate interactions with customers.

Imagine that you run a pizza restaurant and you plan selling pizzas on the internet, but automating the requests in your web. Let’s create a pizzabot!

Follow the instructions bellow to create a basic chatbot in Python and submit a file (.py or .ipynb):

  1. Introduction and welcome.

Initially, the bot has to ask the user’s name. Then, the user will input his/her name. Since we want a polite bot, the bot must print “Hello, {name}!” being {name} the name the user has input before. For example:

Bot:  - Welcome, what’s your name?
User: - Peter
Bot:  - Hello, Peter!
  1. Listening to user’s requests.

The bot will then ask “How can I help you?” and wait for user input.

The available commands that user can input are the following:

  • “available pizzas”

  • “order a pizza”

  • “goodbye”

Depending on the command, the bot will perform different actions (see Point 3). After the action, the bot must start over asking again “How can I help you?” and wait for user input.

This behaviour is repeated in a loop except if the user input is “goodbye”. In this case, the bot will say “Goodbye, {name}!” and exit the program (being {name} the name the user has input in the introduction, see Point 1).

  1. Replying customer’s inquires.

If the command input by the user is “available pizzas”, the bot will answer with a list of the available pizzas to order and the price of each one in parentheses, one pizza on each line, attending to this table:

Pizzas  Price
margarita   5
pepperoni   7
napolitana  7.5
caprichosa  8.5

For example:

Bot:    - How can I help you?
User:   - available pizzas
Bot:    - margarita (5 euros)
    - pepperoni (7 euros)
    - napolitana (7.5 euros)
    - caprichosa (8.5 euros)
Bot:    - How can I help you?

If the command input by the user is “order a pizza”, then the bot will ask “Which pizza?”. The user will choose one pizza from the available pizzas. Then, the bot will answer “Your pizza {pizza} is on the way! Prepare {price} euros”, where {pizza} is the pizza selected by the user and {price} is the price of the pizza selected.

Remember that after attending the user request, the bot must start over asking “How can I help you?”.

For example:

Bot:    - How can I help you?
User:   - order a pizza
Bot:    - Which pizza?
User:   - pepperoni
Bot:    - Your pizza pepperoni is on the way! Prepare 7 euros.
Bot:    - How can I help you?

Another example:

Bot:    - How can I help you?
User:   - order a pizza
Bot:    - Which pizza?
User:   - caprichosa
Bot:    - Your pizza caprichosa is on the way! Prepare 8.5 euros.
Bot:    - How can I help you?

TIP: In order to store the product information, you may use arrays. However, Python dictionaries should be more efficient and neat in this case. For example, for two pizzas:

pizzas = {
    "margarita": 5,
    "pepperoni": 7
}

And for printing the information in the dictionary:

print(pizzas["margarita"])
print(pizzas["pepperoni"])

If you use this example, remember to add napolitana and caprichosa information!

  1. Other cases.

When the bot asks for user input, if the user input is none of the commands described in Point 2, the bot must answer “Sorry, I don’t understand” and start over again and continue listening to user’s requests by asking “How can I help you?” and waiting for another user input.