Because the output of your program will first be preprocessed by an automatic comparison program before being examined by a human being: please follow formatting instructions/examples very carefully. The results your program produces will need to look exactly like the target! Do not embellish with extra titles, blanks, tabs, decimals after integers, or other text. No extras such as "run complete" or "CS212 output" or even an extra space. I will take off points for this. (This is realistic. Most companies run test suites on their products and breaking the test suites is not looked upon well in industry and often the output of one program can be the input to another.) The testing facility of the submit script will help you get this annoying detail right. I hope to make it easy to get it right. Thanks for your patience.

IMPORTANT: be sure the first line in your python file is:

#!/usr/bin/env python3

The Problems

The assignment is to write a set of small executable Python files to get practice with simple Python programming and submitting to test tool. The output of these tools will be easy in that the results are text and comparable to a fixed set of output. The assignment is pretty perscriptive but I think that is good for an opening assignment. The set of four Python files, one for each problem, should be placed in a tar as insructed and under Submission below.

1) Pascal's Triangle

Create a global variable called maxdepth and initialize it to 12.

Write a function fact that takes an integer known to be 0 or greater and returns the factorial of that number. You must use a loop. Include a single line documentation string.

Write a function comb that takes two integers and computes the combination (binomial coefficient): denoted: C(n, k). Use the fact function to compute it in the simple brute force way. (yes, it could be done more efficiently.) Include a single line documentation string.

Write a main function that when called generates lines of Pascal's traiangle upto and including maxdepth combinations. There should be a single space between each entry:

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
1 10 45 120 210 252 210 120 45 10 1
1 11 55 165 330 462 462 330 165 55 11 1 

Call main as the last line in the program. Name this program "pascal.py".

2) Pascal's Triangle of Triangles

Make a copy of the Pascal's Triangle program. Now, instead of printing the combination at each position in the triangle, print the character: '#' if the number at that location is odd and a blank if it is even. Set the global variable called maxdepth to the value 64. Name this program "pascalt.py".

3) Primes

Write a function called isPrime that returns True if the integer argument is a prime and False if not. It assumes the argument is an integer greater than 1. Include a single line documentation string.

Write a main that will list all the primes less than 200, one per line. Call main as the last line in the program. Name this program "primes.py".

4) Factors

Rework the function isPrime to be called factor which returns the smallest factor greater than 1 that goes into its argument. For example for the number 15 it should return 3. For the number 17, which is prime, it should return 17. Include a single line documentation string.

Write a function printFactors that calls factor and prints a list of the prime factors separated by blanks. For example for 90 it would print: 2 3 3 5. Include a single line documentation string.

Write a main that calls printFactors to print the prime factors of all the numbers from 2 upto and including 100. Include a single line documentation string. Call main as the last line in the program. Name this program "factors.py".

Here is first few lines of output. Note the the main prints the number and a colon and then the rest is printed by printFactors

2 : 2
3 : 3
4 : 2 2
5 : 5
6 : 2 3
7 : 7
8 : 2 2 2
9 : 3 3
10 : 2 5
11 : 11
12 : 2 2 3
13 : 13
14 : 2 7
15 : 3 5
16 : 2 2 2 2
17 : 17
18 : 2 3 3
19 : 19
20 : 2 2 5

Submission

Homework will be submitted as an uncompressed tar file that contains no subdirectories. The tar file is submitted to the class submission page. You can submit as many times as you like. The LAST file you submit BEFORE the deadline will be the one graded. Absolutely, no late papers. For all submissions you will receive email at your uidaho address showing how your file performed on the pre-grade tests. The grading program will use more extensive tests, so thoroughly test your program with inputs of your own. Your code should compile and run with runtime errors such as seg faults. If it doesn't it is considered nearly ungradable.

If you have tests you really think are important or just cool please send them to me and I will consider adding them to the test suite.