Fall 2014, David Matuszek

- To familiarize you with functions
- To get you started pair programming

In this assignment you will write a number of functions for testing characteristics of positive integers, plus one special function named `main`

. Each function other than `main`

will take *any* single positive integer as an argument, test whether it has some property, and return a value of either `True`

or `False`

..

Put your program on a file named `figurate_numbers.py`

. Get a copy of the file figurate_numbers_test.py. (As you read this, the file may be missing or incomplete; if so, it will be ready soon.)

`main()`

functionIn the `main`

function, define a variable

and test each of the numbers` 1 `

through` limit`

,
inclusive. Do not use the number 100 elsewhere; use the variable `limit`

instead. This makes the program easier to change if you later want some limit other than 100.

The `main`

function will call each of the other functions, for each of the numbers 1 through `limit`

, to determine the properties of those
numbers. It will then print out each number, one per line, along with a list of its properties
(on the same line).

Your output should look approximately like this:

1 composite, triangular, tetrahedral, square, square pyramidal, pentagonal, not prime oblong, not pointy 2 prime, not triangular, not tetrahedral, not square, not square pyramidal, not pentagonal, not prime oblong, not pointy 3 prime, triangular, not tetrahedral, not square, not square pyramidal, not pentagonal, not prime oblong, not pointy 4 composite, not triangular, tetrahedral, square, not square pyramidal, not pentagonal, not prime oblong, not pointy 5 prime, not triangular, not tetrahedral, not square, square pyramidal, pentagonal, not prime oblong, pointy . . .

The `main`

function doesn't return a value. Each of the other functions is a **predicate**, that is, a function that returns `True`

or `False`

.

`is_prime(n)`

functionA positive number is **prime** if its only positive divisors are itself
and one. For example,` 7 `

is prime because it is evenly divisible
by` 1 `

and` 7`

, but not by any number in between (in particular,
it is not evenly divisible by` 2`

,` 3`

,` 4`

,```
5
```

, or` 6`

).

A positive number is **composite** if it is not prime. For example,```
10
```

is composite because it is evenly divisible by` 2 `

and```
5
```

;` 12 `

is composite because it is evenly divisible by```
2
```

,` 3`

,` 4`

, and` 6`

. As a special case,```
1
```

is considered to be composite.

This function should return `True`

if its argument is a prime number, and `False`

otherwise. Similar statements hold for the other functions.

## The
n) |

## The
n) |

## The
n) |

## The
n) |

## The
n) |

`is_pointy(`*n*)

functionA number is **pointy** (again, my invention, not a standard mathematical term) if it is the sum of two different ~~triangular~~ tetrahedral numbers. The first few
pointy numbers are `5`

(1+4), `11`

(1+10), `14`

(4+10), `21`

(1+9), `24`

(4+20), `30`

(10+20), etc.

At the end of your Python program (after all your function definitions), insert the following lines:

```
if __name__ == "__main__":
main()
```

Here's what this does. If you are in the IDLE window containing your program, and you click `F5`

(or choose `Run -> Run module`

) from the menu, IDLE will automatically run your main function. If you are in the IDLE window containing your test cases (supplied) and click `F5`

or use the menu equivalent, it will run the tests and tell you the results.

The figures and descriptions of tetrahedral, square pyramidal, and pentagonal numbers are from* Mathematics: From the Birth of Numbers* by Jan Gullberg.

This is a pair programming project. Only **one** of you, either you or your team member, should turn in the assignment. Make sure **both** your names are in comments at the top of the file.

Turn in your assignment by **6am, Friday September 12 **. Turn in only the Python file you wrote; don't turn in the supplied test file. As only one file is required, there is no need to zip it.