> For the complete documentation index, see [llms.txt](https://snips.gitbook.io/tutorials/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://snips.gitbook.io/tutorials/t/assistants/skills-101-building-a-simple-calculator-skill.md).

# Apps 101: Building a simple calculator app

{% hint style="danger" %}
This tutorial is outdated and it will be soon updated.
{% endhint %}

## Prerequisites <a href="#prerequisites" id="prerequisites"></a>

For this tutorial, we assume you have the following:

* A Raspberry Pi Model 3
* A speaker (such as the JBL Go)
* A microphone (see for instance our recommendations in the [Microphone Array Benchmark](https://snipsco.github.io/sam/articles/micarrays))
* A Snips account for access to the [Snips Console](https://console.snips.ai/)

## Preparing your device <a href="#preparing-your-device" id="preparing-your-device"></a>

This tutorial is using the Snips Assistant Manager (`sam`) for setting up and deploying the assistant to your Pi. Make sure it is installed on your computer. If not, check out the [Getting Started Guide](https://snips.gitbook.io/getting-started/installation). Once installed, connect to your Pi:

```
$ sam connect
```

Your Pi must be on the same network as your computer. For help on setting up a Pi on a Wi-Fi network, see our [Raspberry Pi Network Connection guide](https://snips.gitbook.io/documentation/installing-snips/on-a-raspberry-pi).

If you haven’t done so already, install the Snips toolbelt on the Pi:

```
$ sam init
```

This will take a little moment, which you may use to start the next step, and create an assistant in the Console.

## Creating the assistant <a href="#creating-the-assistant" id="creating-the-assistant"></a>

Head over to the Snips Console:

[Open Snips Console](https://console.snips.ai/)

Create an account if you don’t have one yet, and create a new assistant with your name of choice. For this tutorial, we will call it “Von Neumann”:&#x20;

![](/files/-LJY6rMDYr13ugNyoZTu)

Add the Calculator bundle, which add intents that detect queries for sums, products, differences and quotients (*don't forget to uncheck Only show apps with actions*):&#x20;

![](/files/-LJY92ndKSVhj2edeXLR)

If you want to add more intents, such as computing the square root of a number, you can do so by adding a new intent to the assistant.

## Adding the app <a href="#adding-the-skill" id="adding-the-skill"></a>

Once the assistant has been created in the Console, you can create the app that will bind intents with the actual action of performing the arithmetic operations and speak the answer. First, create a new project locally on your computer:

```
$ sam create
```

This will generate a [Snipsfile](https://snipsco.github.io/sam/articles/snipsfile) in the current working directory.

### Pointing to your Console assistant <a href="#pointing-to-your-console-assistant" id="pointing-to-your-console-assistant"></a>

Open the Snipsfile, find the line starting with `assistant_url`, and replace it with `assistant_id: YOUR_ASSISTANT_ID`, where `YOUR_ASSISTANT_ID` is the ID of your assistant:

```
assistant_id: YOUR_ASSISTANT_ID
```

The ID can be found in the URL of your assistant in the Console:&#x20;

![](/files/-LJY9CeGnK2ThZBZZ993)

### Adding the handler code <a href="#adding-the-handler-code" id="adding-the-handler-code"></a>

When your created the project above, Sam automatically added a sample app under the `skills` section in the Snipsfile. Remove this section, and replace it with the following:

```
skills:
  - name: calculator
    intents:
      - intent: GetSum
        action: |
          {%
          sum = int(snips.intent.firstTerm) + int(snips.intent.secondTerm)
          snips.dialogue.speak(str(sum))
          %}
      - intent: GetProduct
        action: |
          {%
          product = int(snips.intent.firstTerm) * int(snips.intent.secondTerm)
          snips.dialogue.speak(str(product))
          %}
```

What is happening here? One app, named `calculator`, has been added. It reacts to two intents, `GetSum` and `GetProduct` which are present in the Calculator Bundle.

The `action` section contains a code block with some handler code. The code here is written in Python. It must be delimited by the `{%` and `%}` characters. In this code, an object `snips` is accessible. It gives access to two objects: `snips.intent` and `snips.dialogue`. The `snips.intent` object gives you access to slot values: `firstTerm`and `secondTerm`. The `snips.dialogue` object can be used to speak a sentence, using the `speak()` method.For more information on the `snips` object, see the [Snips Object Reference](https://snipsco.github.io/sam/articles/snips-object).

We leave it to you to add the remaining `GetDifference` and `GetQuotion` intents.

### Testing the app locally <a href="#testing-the-skill-locally" id="testing-the-skill-locally"></a>

Before deploying the assistant to your Pi, it is wise to check that the app works as expected. You can simulate intent messages using the `sam test` command. For instance, to test that the app properly reacts to a `GetSum` intent, enter the following command:

```
$ sam test skill calculator intent=GetSum firstTerm=3 secondTerm=5
```

You should see the output `TTS says: 8`.

## Deploying to your device <a href="#deploying-to-your-device" id="deploying-to-your-device"></a>

Once you are satisfied that your app is working, you can deploy to your device:

```
$ sam deploy
```

After a short time, your assistant should be ready to take your voice commands. Try out:

> Hey Snips, what is 10 times 15

You should hear the answer being spoken out!

If you have any issues, check out our in-depth [Assistant Troubleshooting Guide](https://snipsco.github.io/sam/articles/troubleshooting-guide/).
