Week 2: September 9 - 11
We continue our introduction to Python, and begin to create graphs in IPython Notebook.
Week 2 Notebook
IPython Notebook
- IPython "magics": %run, %pylab
- Saving .png files from notebooks
- Using notebooks to develop and save code
Python
- plot
- Lists
- append
- List indexing and slicing
- List concatenation
- range
- for loops
Weekly Reports
Quiz 1
- Mathematical operations
- Variable assignment
- print
- Boolean expressions
- if
- while
- def
- import
- The dir function
- Comments
Sample Quiz 1
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).
Activity:
- 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.
Tools:
- 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.