> For the complete documentation index, see [llms.txt](https://www.pythonclassroom.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.pythonclassroom.com/math.md).

# Math

## Introduction

You can use Python to solve Math problems!

{% embed url="<https://docs.google.com/presentation/d/1HPQ1KvSYY341tlj7mXA7b2g76qBbz74V5XQAGeFgdHE/edit?usp=sharing>" %}

## Python Math Operators

| Symbol | Operation            |
| ------ | -------------------- |
| +      | addition             |
| -      | subtraction          |
| \*     | multiplication       |
| /      | division             |
| //     | integer division     |
| \*\*   | power or exponent    |
| %      | remainder or modulus |
| ()     | parenthesis          |

{% hint style="info" %}
&#x20;Python follows the Order of Operations, just like you learned in Math class.
{% endhint %}

| Order of Operations Precedence                | Symbols |
| --------------------------------------------- | ------- |
| Parentheses                                   | ()      |
| Exponent                                      | \*\*    |
| Multiplication, Division (from left to right) | \* / // |
| Addition, Subtraction (from left to right)    | + -     |

{% hint style="warning" %}
When doing Math in Python, you must specify multiplication when you want multiplication.  For example: 3(4 + 2) instead of 3 \* (4 + 2) will result in an error.
{% endhint %}

## import math

Python has a number of builtin math methods.

```python
import math

# square root
print(math.sqrt(2))

# pi
print(math.pi)
```

## Examples

Write Python code that does the following:

1. Assign the variable bday to the month of your bday.
2. Multiply bday by 5.
3. Add 6 to bday.
4. Multiply bday by 4.
5. Add 9 to bday.
6. Multiply bday by 5.
7. Add the number number of the day of your bday.
8. Subtract 165 from bday.
9. Print the value of bday.

```python
# Example birthday of 1/1
bday = 1
bday = bday * 5
bday = bday + 6
bday = bday * 4
bday = bday + 9
bday = bday * 5
bday = bday + 1
bday = bday - 165
print(bday)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://www.pythonclassroom.com/math.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
