For Loops

## Description

When we wish to repeat code a certain number of times, we use a For Loop. For Loops are useful for sums, creating tables or seeing how a function changes through different values. A For Loop is created with the syntax `For i in range (a, b):` where i is any variable name (although i is a standard name) and a and b are integers where a < b. Note that the loop starts at a and ends at the value 1 less than b. We will use a For Loop here to print the first 4 derivatives of the function

\begin{equation} f(x) = x^6 + 3x^5 - 41x^4 - 87x^3 + 400x^2 + 444x - 720 \end{equation}

## Sage Cell

Note that any code used in the loop is indented to signal it is part of the loop to Sage.

#### Code

```
f(x) = x^6 + 3*x^5 - 41*x^4 - 87*x^3 + 400*x^2 + 444*x - 720
for i in range(1, 5):
print(diff(f(x), x, i))
```

## Options

None.

## Tags

Primary Tags—Programming: Python

Secondary Tags—Python: Control flow statements

## Related Cells

## Attribute

Permalink:

Author:

Date: 14 Mar 2019 20:21

Submitted by: Zane Corbiere