# Numbers and Math

This page provides syntax for using numbers and mathematic operations in Python. Each section includes an example to demonstrate the described syntax and operations.

## Types of Numbers <a href="#types_of_numbers" id="types_of_numbers"></a>

* Integer (positive and negative counting number) - e.g., -3, -2, -1, 0, 1, 2, and 3:
  * `int` - holds signed integers of non-limited length
  * `long` - holds long integers (exists in Python 2.X, depreciated in Python 3.X)
* Float (real or floating point numbers) - e.g., -2.14, 0.0, and 3.777
  * `float`
* Boolean: (0 = False and 1 = True)
  * `bool`

Use `type()` function to determine type

Input:

```python
# Define two variables x and y
x = 100
y = 3.14

# Print out the variable types for each
print(type(x))
print(type(y))
```

Output:

<pre class="language-python"><code class="lang-python"><strong>&#x3C;class 'int'>
</strong>&#x3C;class 'float'>
</code></pre>

## Arithmetic Operators <a href="#arithmetic_operators" id="arithmetic_operators"></a>

| Operator           | Example  |
| ------------------ | -------- |
| Addition           | x + y    |
| Subtraction        | x - y    |
| Multiplication     | x \* y   |
| Division           | x / y    |
| Floor Division     | x//y     |
| Power (Exponent)   | x \*\* y |
| Remainder (Modulo) | x % y    |

Input:

```python
# Demonstrates different math operations
using f-strings

n1 = 7    # First number
n2 = 3    # Second number
 
# Output results of different math operations
print(f"{n1} + {n2} = {(n1 + n2)}")           # Addition
print(f"{n1} - {n2} = {(n1 - n2)}")           # Subtraction 
print(f"{n1} * {n2} = {(n1 * n2)}")           # Multiplication 
print(f"{n1} / {n2} = {(n1 / n2)}")           # Division 
print(f"{n1} // {n2} = {(n1 // n2)}")         # Floor Division
print(f"{n1} ** {n2} = {(n1 ** n2)}")         # Power/Exponent
print(f"{n1} % {n2} = {(n1 % n2)}")           # Modulo/Remainder
```

Output:

```python
7 + 3 = 10
7 - 3 = 4
7 * 3 = 21
7 / 3 = 2.3333333333333335
7 // 3 = 2
7 ^ 3 = 343
7 % 3 = 1
```

## Comparison Operators and Functions <a href="#comparison_operators_and_functions" id="comparison_operators_and_functions"></a>

Input:

| Operator                 | Example                   |
| ------------------------ | ------------------------- |
| Equality                 | x == y or isequal(x, y)   |
| Inequality               | x != y or !isequal (x, y) |
| Less than                | x < y                     |
| Less than or equal to    | x <= y                    |
| Greater than             | x > y                     |
| Greater than or equal to | x >= y                    |

```python
# compare.py
# Demonstrate comparison operators                                                                               

# Assign values to variables using parallel assignment                                                           
c1, c2, c3, c4 = 25, 50, 75, 50
print(f"  c1 = {c1}, c2 = {c2}, c3 = {c3}), c4 = {c4}")

# Output results of different comparison operations                                                             
 
# Testing equality                                                                                               
print(f"c1 = c3 is {(c1 == c3)}")

# Changing values using abbreviated assignment operators                                                        
c1 *= 3    	# Shorthand for c1 = c1 * 3                                                                       
c4 += 1    	# Shorthand for c4 = c4 + 1                                                                       

print(f"c1 = {c1}, c2 = {c2}, c3 = {c3}, c4 = {c4}")
 
# Testing less than and greater than
print(f"  c1 < c2 is {(c1 < c2)}")
print(f"  c4 <= c2 is {(c4 <= c2)}")
print(f"  c1 > c2 is {(c1 > c2)}")
print(f"  c3 >= c2 is {(c3 >= c2)}")
```

Output:

```python
 c1 = 25, c2 = 50, c3 = 75), c4 = 50
c1 = c3 is False
c1 = 75, c2 = 50, c3 = 75, c4 = 51
  c1 < c2 is False
  c4 <= c2 is False
  c1 > c2 is True
  c3 >= c2 is True
```

## Exercises

* Create a Health Calculator Using Python - *<mark style="color:yellow;">Forthcoming!</mark>*

## Resources

* W3 Schools: [Python Data Types](https://www.w3schools.com/python/python_datatypes.asp)
* W3 Schools: [Python Arithmetic Operators](https://www.w3schools.com/python/gloss_python_arithmetic_operators.asp)
* W3 Schools: [Python Numbers](https://www.w3schools.com/python/python_numbers.asp)


---

# Agent Instructions: 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:

```
GET https://docs.bcbi.brown.edu/codiac-for-health/computing/python/numbers-and-math.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
