0 out of 464 challenges solved
A tetrahedral number, or triangular pyramidal number, represents the number of spheres in a tetrahedron (a pyramid with a triangular base). The nth tetrahedral number can be calculated using the formula:
\[
T(n) = \frac{n \cdot (n + 1) \cdot (n + 2)}{6}
\]
Write a Python function `tetrahedral_number(n)` that takes an integer `n` as input and returns the nth tetrahedral number.
#### Example Usage
```python [main.nopy]
print(tetrahedral_number(1)) # Output: 1
print(tetrahedral_number(4)) # Output: 20
print(tetrahedral_number(5)) # Output: 35
```
#### Constraints
- The input `n` will be a positive integer.
- The function should return an integer value.def tetrahedral_number(n):
"""
Calculate the nth tetrahedral number.
Args:
n (int): The position of the tetrahedral number to calculate.
Returns:
int: The nth tetrahedral number.
"""
# Implement the formula for the nth tetrahedral number
pass