Coding with Python - Syllabus - MC 2018
Instructor: Micheal Pawliuk (University of Calgary)
Time: 10:40 - noon.
Dates: 7/10-7/12, 7/16-7/19, 7/23-7/26. 2018.
Every class will introduce some basic concepts in Python, and give students opportunities to code and play around with the concepts. Every class will have a couple of goal projects that show off the topics learned in that class.
The syllabus is meant to complement the (free) Codecademy Python course. Students can use that course to reinforce and practice outside of class time. It contains other exercises and projects that students may wish to attempt. This class will be specialized towards using Python as a mathematician would use it.
Many of the projects are taken from Project Euler, a collection of math programming challenges.
Week 1 - The basics
1-1. Python Syntax
", Python 2 vs Python 3)
- Variables (
- Arithmetic (data type,
- Updating variables (
- Comments (
- Numbers (
- Booleans (
- Changing data types (
Project: Largest number with small number of characters, Project Euler Problem 6.
1-2. Strings and Printing
- Escaping characters
- Basic string concatination (
- Index and Truncating
- String methods (
- String replacement formatting (
- Input from the user (
Project: Area of a regular polygon.
1-3. Conditionals and Control Flow
- Comparisons, (
- Logical operators(
- Conditionals (
elif, indents, formatting)
- How Python treats non-Booleans
Project: Project Euler 1 (part 1), Pig Latin translator.
Week 2 - Functions, lists and loops!
This week we gain the tools to start doing powerful things. Loops will allow us to get
Python to make tedious, repetitive calculations. What will we ask
Python to do?
2-1. Functions, Import, Random, math.
- Structure/purpose of functions (
def, docstring, body,
- Arguments, parameters (scope)
- Built-in functions (
- Import (
- Math module (
- Random module (
- Other modules. (
Project: Compute e randomly by trials.
- What can go in lists? (strings, integers, lists)
- List methods (
- List splicing and indexing
- Your first
Project: Project Euler 1 (part 2), Project Euler Problem 16
2-3. Loops (
forloop (index, formatting, indent)
- Looping over strings.
- nested loops (order, good naming, runtime)
whileloop (formatting, indent, infinite loops)
else(formatting, when is the else executed)
Project: Make a number guessing game, produce Fibonacci numbers, Prime sieve
2-4. Lists, Dictionaries and Sets
- List comprehesion 1. (using
- List comprehension 2. (using
- Dictionaries: Keys and values
- Defining dictionaries explicitly, by value, by comprehension
- Dictionary Methods (
- Sets: (Defininition, what they are used for, unordered)
- What can go in a set?
- Getting the number of unique elements of a list.
Project: Project Euler Problem 47, Prime Factor decomposition
Week 3 - Advanced basics
This week will be less dense in content to give students a chance to catch up and complete projects.
3-1. Computational thinking and practical concerns
- Making a plan. (Test cases,
- Brute force algorithms.
- Runtime and memory differences (for loops, comprehension, lists vs iterators)
- Debug tools (printing,
- Python 2 vs Python 3, continued.
Project: Project Euler Problems 81, 82, 83 (part 1)
3-2. File input/Output
- Reading files. (open, close, '\n')
- Writing to files. (
Project: Project Euler Problem 13, Project Euler Problems 81, 82, 83 (part 2)
3-3. Numpy, stats and vectors
- Numpy arrays vs lists
- Statistical methods (mean, median, mode, standard deviation, variance)
- Linear regression (using the scipy package)
Project: Interpolating real data
- What is an API? What types are there? (e.g. NASA, ISS, MARTA, Twitter, Youtube)
- What does the data look like? (json)
- API keys (rate limits)
- Making requests
Project: Making a heatmap of Atlanta's bus system