Week 2: September 9 - 11
We continue our introduction to Python, and begin to create graphs in IPython Notebook.
Week 2 Notebook
- IPython "magics": %run, %pylab
- Saving .png files from notebooks
- Using notebooks to develop and save code
- List indexing and slicing
- List concatenation
- for loops
Sample Quiz 1
- Mathematical operations
- Variable assignment
- Boolean expressions
- The dir function
Assignment 1: Pythagorean Triples
Pythagorean triples are positive integer solutions (a, b, c) to the equation a2 + b2 = c2. "Primitive Pythagorean Triples" are those for which a, b, and c are relatively prime (have no common divisor greater than 1).
- Generate all "Primitive Pythagorean Triples" for a, b ≤ 5000.
- See if there is any discernible structure in the PPTs.
- Write a report containing your results and conclusions.
- Use mygcd(a, b) = 1 to check if a and b are relatively prime.
- Need to test if a2 + b2 is a perfect square - write a function to do this.
- Generate graphs using plot to look for patterns.
- Python code for testing your is_square function.